{"id":45513,"date":"2019-07-04T03:01:02","date_gmt":"2019-07-03T17:01:02","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=45513"},"modified":"2019-07-04T07:13:56","modified_gmt":"2019-07-03T21:13:56","slug":"local-fonts-revisited-application-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/local-fonts-revisited-application-tutorial\/","title":{"rendered":"Local Fonts Revisited Application Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Local Fonts Revisited Application Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/lfa_again.jpg\" title=\"Local Fonts Revisited Application Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Local Fonts Revisited Application Tutorial<\/p><\/div>\n<p>It&#8217;s going to take a while to &#8220;bed this in&#8221;, the web application of yesterday&#8217;s <a title='Local Fonts Revisited Recall Tutorial' href='#lfrrt2'>Local Fonts Revisited Recall Tutorial<\/a> involving local font management, and now thinking about &#8220;applying&#8221; local fonts digitized by the user.<\/p>\n<p>We want to explore alternative ideas to &#8230;<\/p>\n<ul>\n<li>character by character traversal of an HTML element (with innerHTML &#8230; the raw textual wording of which can be gleaned via code like (for HTML element object &#8220;divo&#8221;)) &#8230;<br \/>\n<code><br \/>\n var outsidec=('' + (divo.<a target=_blank title='HTML innerText property information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/prop_node_innertext.asp'>innerText<\/a> || divo.contentWindow || divo.contentDocument));<br \/>\n<\/code><br \/>\n &#8230; for chances of &#8220;font character image&#8221; substitution to the innerHTML content &#8230; because it can be slow (though we think we can improve on that slowness, in future code releases) &#8230; so today we look to &#8230;<\/li>\n<li>idea of applying a &#8220;background image strip version of the textual content&#8221; brought to the fore (which can mean retract what&#8217;s there to the back) only where a user defined font character exists &#8230; alas, we discovered (without a lot more effort (we may yet do)) this only suits <a target=_blank title='Monospaced font information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Monospaced_font'>monospaced fonts<\/a> such as Courier New (going back to that decision we made that the digitizing canvas should be 70 x 70)<\/li>\n<\/ul>\n<p>At first we tried that linear gradient thought that a background might &#8220;glow above&#8221; the foreground (tee hee, but seriously, this technique does suit sometimes, as with <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-and-php-base64-media-tutorial\/' title='Javascript and PHP Base64 Media Tutorial'>Javascript and PHP Base64 Media Tutorial<\/a>).  But then we saw sense and to &#8220;retract what&#8217;s there to the back&#8221; we could set the existant element CSS property <i>color:transparent<\/i>, opening the door to the plan below.<\/p>\n<p>The plan we have going forward with this approach goes like &#8230;<\/p>\n<ul>\n<li>find text elements with defined innerHTML &#8230; that &#8230;<\/li>\n<li>have a defined &#8220;ID&#8221; &#8230; and &#8230;<\/li>\n<li>apart from &lt;br&gt; and &amp;gt; and &amp;lt; and &amp;amp; and &amp;nbsp; if innerHTML is equivalent to (innerText || contentWindow || contentDocument) &#8230; we &#8230;<\/li>\n<li>CSS (via Javascript DOM) &#8230;\n<ol>\n<li>document.getElementById(&#8216;arial_span&#8217;).style.color = &#8216;transparent&#8217;;<\/li>\n<li>document.getElementById(&#8216;arial_span&#8217;).style.backgroundRepeat = &#8216;no-repeat&#8217;;<\/li>\n<li>document.getElementById(&#8216;arial_span&#8217;).style.<a target=_blank title='Background size way of covering a parent with a background advice thanks to w3schools' href='https:\/\/www.w3schools.com\/cssref\/playit.asp?filename=playcss_background-size&#038;preval=cover'>backgroundSize<\/a>=&#8217;105% 100%&#8217;;<\/li>\n<li><i>letsomethrough<\/i>( document.getElementById(&#8216;arial_span&#8217;) ).style.backgroundImage = &#8216;URL(&#8220;&#8216; + document.getElementById(&#8216;ifsrc&#8217;).src.replace(&#8216;?ipinto=y&#8217;, document.getElementById(&#8216;ipinto&#8217;).value) + &#8216;&#8221;)&#8217;;<\/li>\n<\/ol>\n<\/li>\n<li>&#8220;spanize&#8221; the parent text element as above via that Javascript <i>function letsomethrough<\/i> by nesting all &#8220;lonely&#8221; (find in code later below where <i>var outside<\/i> is true) text characters within a &#8230;\n<ol>\n<li>span element (why span? &#8230; because it is CSS <i>display:inline<\/i>) &#8230; that if for a letter (as per the &#8220;w&#8221; of below) digitized by the user &#8230;<\/li>\n<li>will inherit its colour from the parent (ie. be transparent, and allow the background imagery to &#8220;shine through&#8221;, via  &lt;span&gt;w&lt;\/span&gt;) &#8230; whereas if for a letter not digitized by the user &#8230;<\/li>\n<li>we define the colour to be black, overriding transparent, via  &lt;span style=&#8221;color:black;&#8221;&gt;w&lt;\/span&gt;<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>As you can see, this is ongoing, and we hope to iron out some of the restrictiveness and get to cross browser issues and &#8220;apply&#8221; to real world data, such as this blog contents, perhaps.<\/p>\n<p>In the meantime, see this idea play out at <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html--GETME\" title=\"under_local_font.html\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html--GETME\" title=\"under_local_font.html\">under_local_font.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\" title=\"Click picture\">live run<\/a> link.<\/p>\n<hr>\n<p id='lfrrt2'>Previous relevant <a target=_blank title='Local Fonts Revisited Recall Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/local-fonts-revisited-recall-tutorial\/'>Local Fonts Revisited Recall Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Local Fonts Revisited Recall Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/lfa.jpg\" title=\"Local Fonts Revisited Recall Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Local Fonts Revisited Recall Tutorial<\/p><\/div>\n<p>Onto yesterday&#8217;s <a title='Local Fonts Revisited Primer Tutorial' href='#lfrpt'>Local Fonts Revisited Primer Tutorial<\/a> Local Fonts web application start, we&#8217;ve progressed today with some &#8220;recall&#8221; work.<\/p>\n<p>In this respect we had to decide a mechanism by which a user could recall their work.   Our decision is to &#8230;<\/p>\n<ul>\n<li>be saving user defined font characters into a long &#8220;canvas&#8221; strip element &#8230; and &#8230;<\/li>\n<li>allow a &#8220;Save&#8221; button be pressed &#8230; to &#8230;<\/li>\n<li>convert that &#8220;canvas&#8221; strip element to data URI and subsequently to a web server image file (via PHP) &#8230; that has a filename whereby &#8230;<\/li>\n<li>on web application rerun if such a Local Fonts web server image file is found (via PHP) &#8230; this triggers &#8230;<\/li>\n<li>a select (dropdown) element appears in the h1 heading element allowing the user to &#8220;recall&#8221; that Local Font work &#8230;in which case &#8230;<\/li>\n<li>a long &#8220;canvas&#8221; strip element appears with these Local Font characters &#8230;  and tomorrow &#8230;<\/li>\n<\/ul>\n<p> &#8230; leaving tomorrow&#8217;s work to &#8220;meld&#8221; that recall data into the natural workflow of that previous work.<\/p>\n<p>It&#8217;s best you view <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html-GETME\" title=\"under_local_font.html\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html-GETME\" title=\"under_local_font.html\">under_local_font.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\" title=\"Click picture\">live run<\/a> link to see what we mean here, getting the [canvasContext].<a target=_blank title='HTML canvas element drawImage() method information from w3schools' href='http:\/\/www.w3schools.com\/tags\/canvas_drawimage.asp'>drawImage<\/a>() functionality to be able to draw multiple images into a single canvas element, the curiosity being that <font color=red>we needed to<\/font> &#8230;<\/p>\n<p><code><br \/>\nfunction athy() {<br \/>\n   var xid='';<br \/>\n   if (lastcid != cid) {<br \/>\n   lastcid=cid;<br \/>\n   <font color=red>compcanv=document.getElementById('compositeimages');<br \/>\n   compcanvc=compcanv.getContext('2d');<\/font><br \/>\n   var isd=docgetclass('athy', 'img');<br \/>\n   for (var jsd=0; jsd&lt;isd.length; jsd++) {<br \/>\n   xid=String.fromCharCode(eval('' + isd[jsd].id.replace('image','')));<br \/>\n   curx=eval(70 * eval('' + origlist.indexOf(xid)));<br \/>\n   compcanvc.drawImage(document.getElementById(isd[jsd].id),0,0,70,70,curx,cury,70,70);<br \/>\n   }<br \/>\n   }<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; a form of verbosity we were not expecting but required because the canvas would clear in between Local Font character definitions.<\/p>\n<hr>\n<p id='lfrpt'>Previous relevant <a target=_blank title='Local Fonts Revisited Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/local-fonts-revisited-primer-tutorial\/'>Local Fonts Revisited Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Local Fonts Revisited Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/localfontagain.jpg\" title=\"Local Fonts Revisited Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Local Fonts Revisited Primer Tutorial<\/p><\/div>\n<p>Working off our work on the Textarea Pointing web application of the series of blog postings ending with <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/textarea-pointing-local-font-canvas-overlay-deletes-tutorial\/' title='Textarea Pointing Local Font Canvas Overlay Deletes Tutorial '>Textarea Pointing Local Font Canvas Overlay Deletes Tutorial<\/a> today we&#8217;re starting out on a Local Fonts web application journey.<\/p>\n<p>At this early stage we&#8217;re missing a bit of accountability and recall but we have worked a way to combine &#8230;<\/p>\n<ul>\n<li>proper web font text characters &#8230; with &#8230;<\/li>\n<li>tailored <a target=_blank title='HTML Canvas element information from w3schools' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>canvas<\/a> drawn &#8220;scribble&#8221; Local Font alternatives &#8230; within a grandchild child <a target=_blank title='HTML iframe element information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_iframe.asp'>iframe<\/a> element &#8230; the in between child <a target=_blank title='HTML iframe element information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_iframe.asp'>iframe<\/a> called via the srcdoc content mode of populating<\/li>\n<\/ul>\n<p>The user can see these characters &#8220;infiltrate&#8221; text strings there on the webpage, one &#8230;<\/p>\n<ol>\n<li>a list of the ascii characters we&#8217;re dealing with using these Local Fonts &#8230; and the other &#8230;<\/li>\n<li>a user controllable HTML div contenteditable=true text string that dynamically changes appropriately as the user defines their Local Font characters<\/li>\n<\/ol>\n<p>Like the idea?  Well, follow the journey in the days to follow today&#8217;s &#8220;proof of concept&#8221; <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html_GETME\" title=\"under_local_font.html\">under_local_font.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/under_local_font.html\" title=\"Click picture\">live run<\/a> link.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d45498' onclick='var dv=document.getElementById(\"d45498\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/contentediable\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d45498' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d45504' onclick='var dv=document.getElementById(\"d45504\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/drawimage\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d45504' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d45513' onclick='var dv=document.getElementById(\"d45513\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/background-image\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d45513' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s going to take a while to &#8220;bed this in&#8221;, the web application of yesterday&#8217;s Local Fonts Revisited Recall Tutorial involving local font management, and now thinking about &#8220;applying&#8221; local fonts digitized by the user. We want to explore alternative &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/local-fonts-revisited-application-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[126,127,2998,184,2442,342,354,2518,418,451,576,587,590,652,2995,2997,932,997,1841,2902,2324,2996,1319,1411],"class_list":["post-45513","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-background","tag-background-image","tag-backgroundsize","tag-canvas","tag-contenteditable","tag-div","tag-dom","tag-drawimage","tag-file","tag-font","tag-html","tag-iframe","tag-image","tag-javascript","tag-local-font","tag-monospaced","tag-php","tag-programming","tag-scribble","tag-srcdoc","tag-todataurl","tag-transparent","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45513"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=45513"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45513\/revisions"}],"predecessor-version":[{"id":45522,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45513\/revisions\/45522"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=45513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=45513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=45513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}