<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Font &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/font/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 07 May 2024 17:00:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>PDFDocument: Font Handling Improvements</title>
		<link>https://blog.xojo.com/2022/04/05/pdfdocument-font-handling-improvements/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 05 Apr 2022 13:30:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9942</guid>

					<description><![CDATA[Xojo 2022r1 brings a bunch of font handling improvements plus new features to the creation of PDF documents. As you probably know, the best way&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Xojo 2022r1 brings a bunch of font handling improvements plus new features to the creation of PDF documents.</p>



<span id="more-9942"></span>



<p>As you probably know, the best way to stay in the &#8220;safe zone&#8221; when using fonts in your PDF files is to use only the Standard 14 fonts: Helvetica, Times, Courier, Zapf Dingbats and Symbol. As part of the PDF standard, these fonts are as close to a &#8220;guarantee&#8221; that the operating system will display the text correctly without needing to embed any fonts as part of the PDF file. As result, the PDF files are smaller when you use on the Standard 14.</p>



<p>But, of course, there are times you need to include more visually captivating fonts in your PDF documents. In these cases, you can use fonts that are already available (installed) in the Fonts folder on the OS. But if you want to use fonts that aren&#8217;t available by default to the Operating System, PDFDocument has improved in this regard in Xojo 2022r1. </p>



<p>First, the fonts cache manager has been improved for speed, decreasing the time required to access and get the font data even when it&#8217;s the first time to be used in text drawing on the PDF document. But not all Operating Systems include the fonts required by the PDF Standard 14, and PDFDocument requires that any font you want to use be installed in the computer/device (or added using AddFonts). Follow these tips:</p>



<ul class="wp-block-list">
<li><strong>macOS</strong> includes by default all the fonts required by the PDF Standard 14, except Monterrey. Where Times is not installed you can use Times New Roman.</li>



<li><strong>Windows</strong> doesn&#8217;t includes Helvetica, Times, Courier or ZapfDingbats. You can use Arial, Times New Roman, Courier New&nbsp;and install ZapfDingbats or any similar font you want to use.</li>



<li><strong>Linux</strong> doesn&#8217;t includes any of the Standard 14 fonts, but you can use some that are equivalent and are installed by default in most of the Linux distributions: Liberation Sans instead of Helvetica, Liberation Serif instead of Times and Liberation Mono instead of Courier. You can install the Symbol and ZapfDingabts font files or any that is equivalent to these.</li>
</ul>



<p>In addition, it is typical for Linux based servers not to have many fonts installed; make sure to install all the font files you intend to use in the creation of your PDF documents.</p>



<h2 class="wp-block-heading">Embedding the Fonts in the PDF</h2>



<p>On the other hand, and because this was a feature requested by several users, we have brought back the EmbeddedFonts property (set by default to False). This way, when you use any font not included among the Standard 14 ones, the data of that fonts won&#8217;t be included either as part of the PDF contents, resulting, thus, in smaller PDF files.</p>


<div class="wp-block-image size-large wp-image-9944 is-style-default">
<figure class="aligncenter"><img fetchpriority="high" decoding="async" width="1024" height="606" src="https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-1024x606.png" alt="" class="wp-image-9944" srcset="https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-1024x606.png 1024w, https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-300x177.png 300w, https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-768x454.png 768w, https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-1536x908.png 1536w, https://blog.xojo.com/wp-content/uploads/2022/02/PDFFileSize-2048x1211.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">This three pages PDF document uses more than 150 fonts, keeping its file size to just 268 KB.</figcaption></figure>
</div>


<p>This feature is especially useful for sharing PDFs with people that have the same set of fonts installed in their OSs, as it is the case in many companies. Additionally, using EmbeddedFonts can considerably reduce the size of the PDFs.</p>



<p>But if the PDF documents created this way are distributed for public or general use, then the end user won&#8217;t have the exact same set of fonts used during the creation of the PDF and, as result, those not available fonts will be substituted and the text won&#8217;t render as expected or was initially designed to (including fonts metrics and styles).</p>



<p>If, on the contrary, the EmbeddedFonts is set to True, then the PDF document will include all the required font information (excluding the data for those in the Standard 14 set) in order to render properly the text, both if the user has those fonts installed or not.</p>



<h2 class="wp-block-heading">Using Fonts Not Installed in the Operating System</h2>



<p>The PDFDocument.AddFonts method has been generally improved and now includes the ability to use fonts <em>not</em> installed when creating PDF Documents in iOS apps created with Xojo.</p>



<p>In this example, I recommend setting the PDFDocument.AddFonts property to True in order to guarantee that the required font data is included as part of the PDF document itself.</p>



<p>Take into consideration the following:</p>



<ol class="wp-block-list">
<li><strong>While using external fonts on Windows</strong>&#8211; Provide AddFonts with a FolderItem pointing to the directory containing the font files.</li>



<li><strong>While using external fonts on macOS</strong>&#8211; macOS requires copying to the Resources &gt; Fonts folder, inside the app bundle, for any font you want to use that is not among those available in the Fonts folder. To do this, add a &#8220;Copy Files&#8221; compilation step to your Xojo project, copying all the fonts you are going to use inside the &#8220;Fonts&#8221; subdirectory and select &#8220;Resources&#8221; as the option in the &#8220;Destination&#8221; entry form the Inspector Panel. In addition, add a text file to the project in the Xojo Navigator (for example named &#8220;ExtraKeys.plist&#8221;) with  the following text: <pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"&gt; &lt;plist version="0.9"&gt; &lt;dict&gt; &lt;key&gt;ATSApplicationFontsPath&lt;/key&gt; &lt;string&gt;Fonts&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt;</pre> </li>



<li><strong>While using external fonts on iOS</strong>&#8211; As it is the case with macOS, iOS requires copying any fonts you want to use in your PDF and that aren&#8217;t already installed to the &#8220;App Parent Folder&#8221;. To do this, add a &#8220;Copy Files&#8221; compilation step to your Xojo project, copying all the font files inside the &#8220;Fonts&#8221; subdirectory, and selecting &#8220;App Parent Folder&#8221; as the Destination in the associated Inspector Panel. In addition, add a text file to your Xojo project (for example named &#8220;iOSKeys.plist&#8221;) whose content will be similar to this: <pre>&lt;?xml version="1.0" encoding="UTF-8"?> &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> &lt;plist version="1.0"> &lt;dict> &lt;key>UIAppFonts&lt;/key> &lt;array> &lt;string><strong>Honey.ttf</strong>&lt;/string> &lt;string><strong>Montserrat-Regular.otf</strong>&lt;/string> &lt;string><strong>Gypsum.ttf</strong>&lt;/string> &lt;/array> &lt;/dict> &lt;/plist>Notice how, in this example, the "Honey.ttf", "Montserrat-Regular.otf" and "Gypsum.ttf" entries are the name of the font files that will be added to the iOS app using the Copy Files compilation step. You'll need to change that names for the font files you're going to use (including the file extension) and make sure that the ".plist" file has as many of these entries as the amount of fonts added to the project using the Copy files compilation step.</pre> <figure><img decoding="async" width="207" height="300" class="wp-image-9943 size-medium aligncenter" src="https://blog.xojo.com/wp-content/uploads/2022/02/iOSFonts-207x300.png" alt="" srcset="https://blog.xojo.com/wp-content/uploads/2022/02/iOSFonts-207x300.png 207w, https://blog.xojo.com/wp-content/uploads/2022/02/iOSFonts-707x1024.png 707w, https://blog.xojo.com/wp-content/uploads/2022/02/iOSFonts.png 750w" sizes="(max-width: 207px) 100vw, 207px" /></figure> <p>For example, this screenshot shows a PDF created on iOS that uses the fonts named in the previous &#8220;.plist&#8221; file.<span style="font-size: 1em;"> </span></p></li>
</ol>



<p><em>Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón</em>, <em>Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at <a href="https://twitter.com/xojoes" target="_blank" rel="noreferrer noopener">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary" target="_blank" rel="noreferrer noopener">Xojo Forum</a>.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>TTC to TTF File Converter</title>
		<link>https://blog.xojo.com/2022/03/24/ttc-to-ttf-file-converter/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Thu, 24 Mar 2022 13:00:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=10107</guid>

					<description><![CDATA[TTC files are TrueType Collection files that contain the data needed to represent multiple font styles and font weights; this is a collection. On the other hand, TTF files are TrueType Font files, that contains the data required to work with only one font style or one font weight (for example: Regular, Bold or Light).]]></description>
										<content:encoded><![CDATA[
<p>TTC files are TrueType Collection files that contain the data needed to represent multiple font styles and font weights; this is a collection. On the other hand, TTF files are TrueType Font files, that contains the data required to work with only one font style or one font weight (for example: Regular, Bold or Light).</p>



<span id="more-10107"></span>



<p>There are a lot of free websites you can use to extract the individual styles and weights from a .ttc file and create .ttf files. But why not do this with Xojo, just for fun … or because I need it! Keep reading and I will show you how.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" width="1280" height="720" src="https://blog.xojo.com/wp-content/uploads/2022/03/37F1D04B-7415-48C6-89C0-F1B64A9BD775.gif" alt="" class="wp-image-10222"/></figure>



<p>Extracting the available styles and weights from TTC files requires parsing its data to find the data chunks required to compose the TTF. That is what we are going to do. Start by creating a new Desktop project (you can adapt it later for any supported Xojo targets like Web or Mobile).</p>



<h3 class="wp-block-heading">Building the TTC to TTF Converter</h3>



<p>All the work is going to be done via a method; but because it will be dealing with font files, it would be a good idea to start by creating our own <code>FontUtilities</code> module. So, add a new module to the project and name it &#8220;FontUtilities&#8221; in the Inspector Panel.</p>



<p>Next, with <code>FontUtilities</code> selected in the Navigator, add a new method to it using the following signature:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> ExtractTTFStylesFromTTC</li>



<li><strong>Parameters:</strong> inputFile As FolderItem, outputFolder As FolderItem</li>



<li><strong>Scope:</strong> Public</li>
</ul>



<p>And add the following code into the associated Code Editor:</p>



<pre class="wp-block-preformatted">#Pragma DisableBackgroundTasks
#Pragma DisableBoundsChecking
#Pragma StackOverflowChecking False

If inputFile = Nil Or Not inputFile.Exists Then Return
If outputFolder = Nil Or Not outputFolder.IsFolder Or Not outputFolder.IsWriteable Then Return

Var mb As MemoryBlock

Var rb As BinaryStream = BinaryStream.Open(inputFile)
mb = rb.Read(inputFile.Length)
mb.LittleEndian = False
rb.Close

If mb &lt;&gt; Nil Then
  
  Var OutputBuffers() As MemoryBlock
  
  // Let's make sure this is a .ttc file by checking the first four bytes of the header
  
  If mb.StringValue(0, 4) &lt;&gt; "ttcf" Then Return
  
  // offset for the total of faces/styles in the ttc file
  Var totalFaces As Integer = mb.UInt32Value(8)
  
  Var tableHeaderOffset As Integer
  Var tableCount As UInt16
  Var headerLength, tLength, tableLength, totalLength, currentOffset As Integer
  
  Var outputBuffer As MemoryBlock
  
  For n As Integer = 0 To totalFaces - 1
    
    // 0x0c is the first possition of the tableHeader offsets
    tableHeaderOffset = mb.UInt32Value(12 + (n * 4))
    
    // offset to the table count from the current table header offset
    tableCount = mb.UInt16Value(tableHeaderOffset+4) 
    
    headerLength = 12 + tableCount * 16
    
    tableLength = 0 
    
    For j As Integer = 0 To tableCount - 1
      
      tLength = mb.UInt32Value(tableHeaderOffset+12+12+(j*16))
      tableLength = tableLength + Bitwise.BitAnd(tLength + 3, Bitwise.OnesComplement(3)) // next value multiple of four
    Next
    
    totalLength = headerLength + tableLength
    
    outputBuffer = New MemoryBlock(totalLength)
    outputBuffer.LittleEndian = False
    
    //Copy table to the buffer for the new file
    outputBuffer.StringValue(0,headerLength - 1) = mb.StringValue(tableHeaderOffset, headerLength - 1)
    
    currentOffset = headerLength
    
    Var tOffset, tOtherLength As Integer
    
    For j As Integer = 0 To tableCount - 1
      tOffset = mb.UInt32Value(tableHeaderOffset + 12 + 8 + (j * 16))
      tOtherLength = mb.UInt32Value(tableHeaderOffset + 12 + 12 + (j * 16))
      outputBuffer.UInt32Value(12 + 8 + (j * 16)) = currentOffset
      
      // Copy data to the buffer for the new file
      outputBuffer.StringValue(currentOffset, tOtherLength - 1) = mb.StringValue(tOffset, tOtherLength - 1)
      
      outputBuffer.UInt32Value(currentOffset) = mb.UInt32Value(tOffset)
      currentOffset = currentOffset + Bitwise.BitAnd(tOtherLength + 3, Bitwise.OnesComplement(3)) // next value multiple of four
    Next
    outputBuffers.Add(outputBuffer)
  Next
  
  // Let's create the .ttf files in the output folder
  Var max As Integer = outputBuffers.Count - 1
  Var outputFile As FolderItem
  
  For n As Integer = 0 To max
    outputFile = outputFolder.Child(inputFile.Name.NthField(".", 1) + " " + n.ToString + ".ttf")
    Var ob As BinaryStream = BinaryStream.Create(outputFile)
    ob.Write(outputBuffers(n))
    ob.Close
  Next
End If</pre>



<h3 class="wp-block-heading">Testing the TTC to TTF Converter</h3>



<p>Now, let&#8217;s create a minimal user interface in order to test it. Select the <code>Window1</code> window in the Navigator in order to bring up the Layout Editor. Next, drag a <code>DesktopButton</code> from the Library and drop it inside the window area in the Layout Editor. Use the alignment guides to help you to leave enough room between the button and the window margins.</p>



<p>Double click the button in the Layout Editor to open the Add Event Handler dialog box. The <code>Pressed</code> Event Handler should be selected already, so simply confirm it clicking on the &#8220;OK&#8221; button.</p>



<p>The <code>Pressed</code> Event Handler has been added under <code>Button1</code> in the Navigator and with its associated Code Editor visible in the main area, type the following lines of code:</p>



<pre class="wp-block-preformatted">Var inputFontFile As FolderItem = FolderItem.ShowOpenFileDialog(".ttc")
Var outputFolder As FolderItem = FolderItem.ShowSelectFolderDialog

FontUtilities.ExtractTTFStylesFromTTC(inputFontFile, outputFolder)</pre>



<p>The first line of code will ask the user to select the &#8220;.ttc&#8221; font file to process, and the second line will ask for the destination folder where the output (the converted .ttf font files) will be stored. Finally, the third line of code is the one calling our <code>ExtractTFFStylesFromTTC</code> method passing along both the file to process and the output folder.</p>



<p>That&#8217;s all! Click on the Run button in the main toolbar of the Xojo IDE. Once the app is running, click on the button to select any &#8220;.ttc&#8221; file you want to process. Next, the app will ask you to select the output folder and you will be able to see the extracted files inside the selected output folder.</p>



<p><em>Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón</em>, <em>Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at <a href="https://twitter.com/xojoes" target="_blank" rel="noreferrer noopener">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary" target="_blank" rel="noreferrer noopener">Xojo Forum</a>.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Font Family Listing on Windows</title>
		<link>https://blog.xojo.com/2022/03/14/font-family-listing-on-windows/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Mon, 14 Mar 2022 17:15:39 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=10102</guid>

					<description><![CDATA[Do you need to display all the font family members (styles and weights) available in your Windows computer? There is a simple way to do it using the RegistryItem class! Continue reading and I'll show you how.]]></description>
										<content:encoded><![CDATA[
<p>Do you need to display all the font family members (styles and weights) available in your Windows computer? There is a simple way to do it using the RegistryItem class! Continue reading and I&#8217;ll show you how.</p>



<span id="more-10102"></span>



<p>As you may know, when you use the <code>System.FontCount</code> and <code>System.FontAt</code> functions on macOS they retrieve the total number of fonts and every style available for the app. Though this is not the case when both functions are used on Windows, there is a simple way for you to retrieve all the fonts and styles available on Windows, including the underlying font file where a particular font style is stored.</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="1024" height="715" src="https://blog.xojo.com/wp-content/uploads/2022/03/ListadoMenu-1024x715.png" alt="" class="wp-image-10104" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/ListadoMenu-1024x715.png 1024w, https://blog.xojo.com/wp-content/uploads/2022/03/ListadoMenu-300x209.png 300w, https://blog.xojo.com/wp-content/uploads/2022/03/ListadoMenu-768x536.png 768w, https://blog.xojo.com/wp-content/uploads/2022/03/ListadoMenu.png 1034w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<h3 class="wp-block-heading">Building the WindowsFonts Class</h3>



<p>In order to do this, create a new Desktop project on Xojo and add a new Class named WindowsFonts.</p>



<p>Select the <code>WindowsFonts</code> class in the Navigator and add a new Method to it using the following values in the Inspector panel:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> Constructor</li><li><strong>Scope:</strong> Private</li></ul>



<p>Then add the following snippet of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">availableFonts = New Dictionary
Var rFonts As New RegistryItem("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts")

If rFonts &lt;&gt; Nil Then
    Var Max As Integer = rFonts.KeyCount-1
    For n As Integer = 0 To Max
        availableFonts.Value(rFonts.name(n).NthField("(",1).Trim) = rFonts.Value(n)
    Next
End If</pre>



<p>Now add the availableFonts property to the class using the following data in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Property Name:</strong> availableFonts</li><li><strong>Type:</strong> Dictionary</li></ul>



<p>Next, create the Shared Methods that the class will expose to the user. The first one will be the one responsible of creating the shared instance for the class. Add a new Shared Method and use the following data in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> Init</li><li><strong>Scope:</strong> Private</li></ul>



<p>Next, enter the following line in the associated Code Editor:</p>



<pre class="wp-block-preformatted">sharedInstance = new WindowsFonts</pre>



<p>Now add a second Shared Method to the class using the following data in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> fonts</li><li><strong>Return Type:</strong> String()</li><li><strong>Scope:</strong> Public</li></ul>



<p>Type the following snippet of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">If sharedInstance = Nil Then init
Var fonts() As String
For Each item As Variant In sharedInstance.availableFonts.Keys
    fonts.add item.StringValue
Next item
Return fonts</pre>



<p>The last shared method will be responsible for returning the name of the backing file for a particular font style. Add a third Shared Method using the following data in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> FileNameForFont</li><li><strong>Parameters:</strong> fontName As String</li><li><strong>Return Type:</strong> String</li><li><strong>Scope:</strong> Public</li></ul>



<p>And type these two lines of code in the resulting Code Editor:</p>



<pre class="wp-block-preformatted">If sharedInstance = Nil Then Init
If sharedInstance.availableFonts.HasKey(fontName) Then Return sharedInstance.availableFonts.Value(fontName)</pre>



<p>The last thing we need to do is add a Shared Property to the class. This property will store a reference to the shared WindowsFont class instance. Add a new Shared Property using the following values in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Property Name:</strong> sharedInstance</li><li><strong>Type:</strong> WindowsFonts</li><li><strong>Scope:</strong> Protected</li></ul>



<p>That&#8217;s all. Now, let&#8217;s create a simple user interface to test it.</p>



<h3 class="wp-block-heading">Testing the WindowsFonts Class</h3>



<p>Select the <code>Windows1</code> window in the Navigator so it is displayed in the Layout Editor. Next, drag a <code>DesktopPopupMenu</code> from the Library and drop it near to the top-left corner of the window in the Layout (use the alignment guides to help you know where to drop it, leaving enough space at the top and left margins of the <code>Window1</code> window).</p>



<p>With <code>PopupMenu1</code> selected in the Layout Editor, drag the middle-right resizing handler to make the width enough to display the font names. In addition, change the Name in the associated Inspector Panel to &#8220;FontSelector&#8221;.</p>



<p>Drag a <code>DesktopLabel</code> from the Library and drop it in the Layout Editor below the <code>FontSelector</code> PopupMenu. Next, change the <code>Text</code> property in the associated Inspector Panel to &#8220;Font File:&#8221;, and use the resizing handlers in the Layout Editor so it is wide enough to display the text in the label.</p>



<p>Drag a second <code>DesktopLabel</code> from the Library and drop it to the right of the previous one. This is the label we will be using to display the name of the selected font in the PopupMenu. Use the resizing handlers to make it wide enough and change the <code>Text</code> property to an empty string.</p>



<p>The user interface layout should look like the one displayed in this image:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="851" height="632" src="https://blog.xojo.com/wp-content/uploads/2022/03/Layout.png" alt="" class="wp-image-10103" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/Layout.png 851w, https://blog.xojo.com/wp-content/uploads/2022/03/Layout-300x223.png 300w, https://blog.xojo.com/wp-content/uploads/2022/03/Layout-768x570.png 768w" sizes="auto, (max-width: 851px) 100vw, 851px" /></figure></div>



<p>Select the <code>FontSelector</code> item in the Layout Editor and double-click on it in order to display the Add Handler Event Dialog Box. Here we want to select the <code>Opening</code> and <code>SelectionChanged</code> Event Handlers. Once selected, click the &#8220;OK&#8221; button so these are added to the <code>FontSelector</code> item in the Navigator.</p>



<p>Select the just added <code>Opening</code> Event Handler in the Navigator under <code>FontSelector</code> to access the associated Code Editor and type the following line of code:</p>



<pre class="wp-block-preformatted">Me.AddAllRows WindowsFonts.Fonts</pre>



<p>Next, select the <code>SelectionChanged</code> Event Handler entry under <code>FontSelector</code> in the Navigator and type the following line of code:</p>



<pre class="wp-block-preformatted">FontFileLabel.Text = WindowsFonts.FileNameForFont(item.Text)</pre>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="775" height="270" src="https://blog.xojo.com/wp-content/uploads/2022/03/FileForFont.png" alt="" class="wp-image-10105" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/FileForFont.png 775w, https://blog.xojo.com/wp-content/uploads/2022/03/FileForFont-300x105.png 300w, https://blog.xojo.com/wp-content/uploads/2022/03/FileForFont-768x268.png 768w" sizes="auto, (max-width: 775px) 100vw, 775px" /></figure></div>



<p>That&#8217;s all. Run the test app, and you&#8217;ll see all the fonts, styles and widths of those fonts that are available on your Windows computer. Change the selected entry in the PopupMenu and you&#8217;ll see the associated font file name reflected in the label below it.</p>



<p><em>Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at <a href="https://goto10.substack.com" target="_blank" rel="noreferrer noopener">Goto 10</a> and </em>on Mastodon @lefebvre@hachyderm.io.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>QuickTip: Using SF Symbols in macOS … revisited!</title>
		<link>https://blog.xojo.com/2021/10/21/quicktip-using-sf-symbols-in-macos-revisited/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Thu, 21 Oct 2021 13:00:00 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[SF Font]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9397</guid>

					<description><![CDATA[Earlier this year ago I wrote a post about using the SF Font symbols on macOS Picture.SystemImagein iOS apps. However that technique has some downsides. For one, the symbol glyphs are hardcoded, which means that it's not possible to access the new symbols added to the SF Font by Apple. In addition, it isn't possible to set the font weight and scale for the glyph. In this new post, I'll show a more flexible way to work with these symbols on macOS 11+.]]></description>
										<content:encoded><![CDATA[
<p>Earlier this year ago I wrote a post about using <a href="https://blog.xojo.com/2021/02/17/quicktip-using-sf-symbols-in-your-macos-apps/">the SF Font symbols on macOS</a> <code>Picture.SystemImage</code>in <strong>iOS</strong> apps. However that technique has some downsides. For one, the symbol glyphs are hardcoded, which means that it&#8217;s not possible to access the new symbols added to the SF Font by Apple. In addition, it isn&#8217;t possible to set the font weight and scale for the glyph. In this new post, I&#8217;ll show a more flexible way to work with these symbols on macOS 11+.</p>



<span id="more-9397"></span>



<p>This technique is more on par with the current <code>Picture.SystemImage</code> you use in your Xojo iOS apps. With it you will be able to set the following attributes:</p>



<ul class="wp-block-list"><li><strong>Glyph name.</strong> You can use Apple&#8217;s Symbols SF utility to view all the available symbols and the name associated with each of these.</li><li><strong>Size</strong> (in points)</li><li><strong>Weight.</strong> The weight of the SF Font, ranging from Ultra-Light to Black. This is an Enumeration value.</li><li><strong>Scale.</strong> The scale of the SF Font symbol, ranging from Small to Large. This is an Enumeration value.</li><li><strong>TemplateColor.</strong> If you want to tint the resulting glyph, you can provide a ColorGroup parameter (Desktop apps) or a regular Color parameter (Desktop, Console apps).</li><li><strong>FallbackTemplateImage.</strong> You can provide a grayscale / black and white image to use as a fallback image, in case there is no way to create a picture from the received &#8220;name&#8221; string.</li></ul>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="1024" height="851" src="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.43.57-1024x851.png" alt="" class="wp-image-9400" srcset="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.43.57-1024x851.png 1024w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.43.57-300x249.png 300w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.43.57-768x639.png 768w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.43.57.png 1424w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>As it is the case with the existing iOS method, you will receive a Picture. For example you will be able to use code like this in your desktop projects:</p>



<pre class="wp-block-preformatted">Var c As New ColorGroup(Color.Red, Color.White)
Var p As Picture = SystemImage("highlighter", 120.0, SystemImageWeights.UltraLight, Symbolscale.Small, c, fallback)

IVSFGlyph.Image = p</pre>



<p>The &#8220;fallback&#8221; parameter refers to an image added to a desktop project that will be used if the glyph is not found. This will produce the following glyph, assigned as the image to the <code>ImageView</code> control named <code>IVSFGlyph</code>:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="724" height="522" src="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.25.15.png" alt="" class="wp-image-9398" srcset="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.25.15.png 724w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.25.15-300x216.png 300w" sizes="auto, (max-width: 724px) 100vw, 724px" /></figure></div>



<p>In order to add this kind of functionality to your Xojo Desktop and Console projects on macOS, add a new Module to the Navigator (for example, with the name macOSLib). Then, with the macOSLib item selected in the Navigator, add two enumerations with the following values:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> SymbolScale</li><li><strong>Type:</strong> Integer</li><li><strong>Scope:</strong> Global</li><li><strong>Values:</strong><br>Small = 1<br>Medium = 2<br>Large = 3</li></ul>



<ul class="wp-block-list"><li><strong>Name:</strong> SystemImageWeights</li><li><strong>Type:</strong> Integer</li><li><strong>Values:</strong><br>UltraLight = 0<br>Thin = 1<br>Light = 2<br>Regular = 3<br>Medium = 4<br>Semibold = 5<br>Bold = 6<br>Heavy = 7<br>Black = 8</li></ul>



<p>Now add to the <code>macOSLib</code> module the method that will run both on Desktop and Console macOS apps:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> SystemImage</li><li><strong>Parameters:</strong> name As String, size As Double, weight As SystemImageWeights = SystemImageWeights.Regular, scale As SymbolScale = SymbolScale.Medium, templateColor As Color, fallbackTemplateImage As Picture = Nil</li><li><strong>Return Type:</strong> Picture</li><li><strong>Scope:</strong> Global</li></ul>



<p>Click on the cog wheel icon in the Inspector to change to the attributes section for the method, and make sure to set only the options displayed in the following picture:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="496" height="336" src="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.32.25.png" alt="" class="wp-image-9399" srcset="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.32.25.png 496w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.32.25-300x203.png 300w" sizes="auto, (max-width: 496px) 100vw, 496px" /></figure></div>



<p>Finally, put the following code in the Code Editor associated with the newly created method:</p>



<pre class="wp-block-preformatted">#If TargetMacOS

  If System.Version &gt;= "11.0" Then

    If name = "" Then Return Nil

    Declare Function Alloc Lib "Foundation" Selector "alloc" (classRef As Ptr) As Ptr
    Declare Sub AutoRelease Lib "Foundation" Selector "autorelease" (classInstance As Ptr)

    Declare Function NSClassFromString Lib "Foundation" (clsName As CFStringRef) As Ptr
    Declare Function ImageWithSystemSymbolName Lib "AppKit" Selector "imageWithSystemSymbolName:accessibilityDescription:" (imgClass As Ptr, symbolName As CFStringRef, accesibility As CFStringRef) As Ptr
    Declare Function ConfigurationWithPointSize Lib "AppKit" Selector "configurationWithPointSize:weight:scale:" (symbolConfClass As Ptr, size As CGFloat, weight As CGFloat, tscale As SymbolScale) As Ptr
    Declare Function ImageWithSymbolConfiguration Lib "AppKit" Selector "imageWithSymbolConfiguration:" (imgClass As Ptr, config As Ptr) As Ptr
    Declare Function ColorWithRGBA Lib "Foundation" Selector "colorWithRed:green:blue:alpha:" (nscolor As ptr, red As CGFloat, green As CGFloat, blue As CGFloat, alpha As CGFloat) As Ptr
    Declare Sub SetTemplate Lib "AppKit" Selector "setTemplate:" (imageObj As Ptr, value As Boolean)
    Declare Sub LockFocus Lib "AppKit" Selector "lockFocus" (imageObj As Ptr)
    Declare Sub UnlockFocus Lib "AppKit" Selector "unlockFocus" (imageObj As Ptr)
    Declare Sub Set Lib "Foundation" Selector "set" (colorObj As Ptr)
    Declare Sub NSRectFillUsingOperation Lib "AppKit" (rect As NSRect, option As UInteger)

    Declare Function RepresentationUsingType Lib "AppKit" Selector "representationUsingType:properties:" (imageRep As Ptr, type As UInteger, properties As Ptr) As Ptr
    Declare Function InitWithFocusedView Lib "AppKit" Selector "initWithFocusedViewRect:" (imageObj As Ptr, rect As NSRect) As Ptr

    Var nsimage As Ptr = NSClassFromString("NSImage")
    Var orImage As Ptr = ImageWithSystemSymbolName(nsimage, name, "")
    Var symbolConfClass As Ptr = NSClassFromString("NSImageSymbolConfiguration")

    // Getting the weight as the required SystemImageWeight float
    Var tWeight As CGFloat = SystemImageWeight(weight)

    // Creating a configuration obj for the Glyph
    Var symbolConf As Ptr = ConfigurationWithPointSize(symbolConfClass, size, tWeight, scale)

    // Getting the final NSImage from the Glyph + Conf (still in vectorial format)
    Var finalImage As Ptr = ImageWithSymbolConfiguration(orImage, symbolConf)

    // Can't create image from received glyph name, so we return Nil if fallback is not provided
    // or colorize the fallback image if there is one
    If finalImage = Nil Then

      If fallbackTemplateImage = Nil Then Return Nil

      Var fallbackData As MemoryBlock = fallbackTemplateImage.ToData(Picture.Formats.PNG)
      Var fallbackDataPtr As Ptr = fallbackData

      Declare Function DataWithBytesLength Lib "Foundation" Selector "dataWithBytes:length:" (dataClass As Ptr, data As Ptr, length As UInteger) As Ptr

      If fallbackData &lt;&gt; Nil And fallbackData.Size &gt; 0 Then

        Var NSDataClass As Ptr = NSClassFromString("NSData")
        Var NSDataObj As Ptr = DataWithBytesLength(NSDataclass, fallbackDataPtr, fallbackData.Size)

        If NSDataObj &lt;&gt; Nil Then

          Declare Function InitWithData Lib "AppKit" Selector "initWithData:" (imageInstance As Ptr, data As Ptr) As Ptr

          Var NSImageClass As Ptr = NSClassFromString("NSImage")

          finalImage = Alloc(NSImageClass)
          finalImage = InitWithData(finalImage, NSDataObj)

          AutoRelease(NSDataObj)

        End If

      End If

    End If

    If finalImage = Nil Then Return Nil

    Var c As Color
    Var nscolor As Ptr

    LockFocus(finalImage)

    // Applying tint to the image if we receive a valid ColorGroup object

    c = templateColor

    nscolor = NSClassFromString("NSColor")
    Var tColor As Ptr = ColorWithRGBA(nscolor, c.Red/255.0, c.Green/255.0, c.Blue/255.0, 1.0-c.Alpha/255.0)

    // We need to set the Template property of the NSImage to False in order to colorize it.
    SetTemplate(finalImage, False)

    Declare Function ImageSize Lib "AppKit" Selector "size" (imageObjt As Ptr) As NSSize

    Var tRect As NSRect

    tRect.Origin.X = 0
    tRect.Origin.Y = 0
    tRect.RectSize = ImageSize(finalImage)

    Set(tColor)
    NSRectFillUsingOperation(tRect, 3)

    // Getting bitmap image representation in order to extract the data as PNG.

    Var NSBitmapImageRepClass As Ptr = NSClassFromString("NSBitmapImageRep")
    Var NSBitmapImageRepInstance As Ptr = Alloc(NSBitmapImageRepClass)
    Var newRep As Ptr = InitWithFocusedView(NSBitmapImageRepInstance, tRect)

    UnlockFocus(finalImage)

    Var data As Ptr = RepresentationUsingType(newRep, 4, Nil) // 4 = PNG

    AutoRelease(newRep)
    AutoRelease(nscolor)

    // Getting image data to generate the Picture object in the Xojo side

    Declare Function DataLength Lib "Foundation" Selector "length" (obj As Ptr) As Integer
    Declare Sub GetDataBytes Lib "Foundation" Selector "getBytes:length:" (obj As Ptr, buff As ptr, len As Integer)

    // We need to get the length of the raw data…
    Var dlen As Integer = DataLength(data)

    // …in order to create a memoryblock with the right size
    Var mb As New MemoryBlock(dlen)
    Var mbPtr As Ptr = mb

    // And now we can dump the PNG data from the NSDATA objecto to the memoryblock
    GetDataBytes(data, mbPtr, dlen)

    // In order to create a Xojo Picture from it
    Return Picture.FromData(mb)
  End If

#EndIf</pre>



<p>As you can see, this method calls the <code>SystemImageWeight</code> method, and also makes use of some <code>Structs</code>. Let&#8217;s add to the method that will convert the received enum value to the required <code>CGFloat</code> value needed by the Declare:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> SystemImageWeight</li><li><strong>Parameters:</strong>&nbsp;<span style="font-size: revert;">weight As SystemImageWeights</span></li><li><strong>Returned Type:</strong> CGFloat</li><li><strong>Scope:</strong> Global</li></ul>



<p>Add the following code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">Var tWeight As CGFloat = 0

Select Case weight
Case SystemImageWeights.UltraLight
  tWeight = -1.0
Case SystemImageWeights.Thin
  tWeight = -0.75
Case SystemImageWeights.Light
  tWeight = -0.5
Case SystemImageWeights.Regular
  tWeight = -0.25
Case SystemImageWeights.Medium
  tWeight = 0
Case SystemImageWeights.Semibold
  tWeight = 0.25
Case SystemImageWeights.Bold
  tWeight = 0.5
Case SystemImageWeights.Heavy
  tWeight = 0.75
Case SystemImageWeights.Black
  tWeight = 1
End Select

Return tWeight</pre>



<p>And now add three new Structures to the macOSLib module using the following values:</p>



<ul class="wp-block-list"><li><strong>Structure Name:</strong> NSOrigin</li><li><strong>Scope:</strong> Global<br>X as CGFloat<br>Y as CGFloat</li></ul>



<ul class="wp-block-list"><li><strong>Structure Name:</strong> NSSize</li><li><strong>Scope:</strong> Global<br>Height as CGFloat<br>Width as CGFloat</li></ul>



<ul class="wp-block-list"><li><strong>Structure Name:</strong> NSRect</li><li><strong>Scope:</strong> Global<br>Origin as NSOrigin<br>RectSize as NSSize</li></ul>



<p>Add an overloaded method only intended for macOS desktop apps. The main difference is that this one can receive a <code>ColorGroup</code> parameter instead of just a <code>Color</code> object:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> SystemImage</li><li><strong>Parameters:</strong> name As String, size As Double, weight As SystemImageWeights = SystemImageWeights.Regular, scale As SymbolScale = SymbolScale.Medium, templateColor As ColorGroup = Nil, fallbackTemplateImage As Picture = Nil</li><li><strong>Returned Type:</strong> Picture</li><li><strong>Scope:</strong> Global</li></ul>



<p>And type the following code in the associated Code Editor for the method:</p>



<pre class="wp-block-preformatted">Var c As Color

If templateColor &lt;&gt; Nil Then
  c = templateColor
End If

Return SystemImage(name, size, weight, scale, c, fallbackTemplateImage)</pre>



<p>Click on the cog wheel icon from the method Inspector and set the attributes as shown in the following picture:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="476" height="330" src="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.50.17.png" alt="" class="wp-image-9401" srcset="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.50.17.png 476w, https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-15.50.17-300x208.png 300w" sizes="auto, (max-width: 476px) 100vw, 476px" /></figure></div>



<h2 class="wp-block-heading">&nbsp;</h2>



<h2 class="wp-block-heading">Setting SF Glyphs directly to Views</h2>



<p>Let&#8217;s add now a third method to the module whose main difference is that it will not return a Picture; instead, it will set the specified SF glyph as the image for the received control handler. For example, this is neat if you want to set a SF symbol to a button in you UI interface (among other UI controls).</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="192" height="70" src="https://blog.xojo.com/wp-content/uploads/2021/10/Captura-de-pantalla-2021-10-04-a-las-16.13.14.png" alt="" class="wp-image-9402"/></figure></div>



<p>This is the signature for the new method:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> SystemImage</li><li><strong>Parameters:</strong> name As String, size As Double, weight As SystemImageWeights = SystemImageWeights.Regular, scale As SymbolScale = SymbolScale.Small, controlHandler As Integer</li><li><strong>Scope:</strong> Global</li></ul>



<p>And the code to put in the associated Code Editor:</p>



<pre class="wp-block-preformatted">#If TargetMacOS

  If System.Version &gt;= "11.0" Then

    If name = "" Then Exit

    Declare Function Alloc Lib "Foundation" Selector "alloc" (classRef As Ptr) As Ptr
    Declare Sub AutoRelease Lib "Foundation" Selector "autorelease" (classInstance As Ptr)

    Declare Function NSClassFromString Lib "Foundation" (clsName As CFStringRef) As Ptr
    Declare Function ImageWithSystemSymbolName Lib "AppKit" Selector "imageWithSystemSymbolName:accessibilityDescription:" (imgClass As Ptr, symbolName As CFStringRef, accesibility As CFStringRef) As Ptr
    Declare Function ConfigurationWithPointSize Lib "AppKit" Selector "configurationWithPointSize:weight:scale:" (symbolConfClass As Ptr, size As CGFloat, weight As CGFloat, scale As SymbolScale) As Ptr
    Declare Function ImageWithSymbolConfiguration Lib "AppKit" Selector "imageWithSymbolConfiguration:" (imgClass As Ptr, config As Ptr) As Ptr

    Var nsimage As Ptr = NSClassFromString("NSImage")
    Var orImage As Ptr = ImageWithSystemSymbolName(nsimage, name,"")
    Var symbolConfClass As Ptr = NSClassFromString("NSImageSymbolConfiguration")

    // Getting the weight as the required SystemImageWeight float
    Var tWeight As CGFloat = SystemImageWeight(weight)

    // Creating a configuration obj for the Glyph
    Var symbolConf As Ptr = ConfigurationWithPointSize(symbolConfClass, size, tWeight, scale)

    // Getting the final NSImage from the Glyph + Conf (still in vectorial format)
    Var finalImage As Ptr = ImageWithSymbolConfiguration(orImage, symbolConf)

    // We need to know if the received Handler can respond to the setImage message (that is, it's a View)

    Declare Function RespondsToSelector Lib "/usr/lib/libobjc.A.dylib" Selector "respondsToSelector:" (obj As Integer, sel As Ptr) As Boolean
    Declare Function NSSelectorFromString Lib "Foundation" (sel As CFStringRef) As Ptr

    Var sel As Ptr = NSSelectorFromString("setImage:")

    // We check if it's a valid handler, we have an NSImage object and the handler can receive the "setImage" message
    If controlHandler &lt;&gt; 0 And finalImage &lt;&gt; Nil And RespondsToSelector(controlHandler, sel) Then

      Declare Sub Set Lib "AppKit" Selector "setImage:" (control As Integer, Image As Ptr)

      // We set the NSImage to the received control
      Set(controlHandler, finalImage)

    End If

  End If

#EndIf</pre>



<p>So, for example, you can set now the Gear symbol as the image of a <code>PushButton</code> control added to the app UI using the following code in the <code>Open</code> Event Handler of the <code>PushButton</code> instance:</p>



<pre class="wp-block-preformatted">SystemImage("gearshape.2", 14.0, SystemImageWeights.Regular, SymbolScale.Small, Me.Handle)</pre>



<h2 class="wp-block-heading">Summary</h2>



<p>And that&#8217;s all! As you can see, there are no hardcoded codepoints for the SF glyphs. You&#8217;ll be able to create a picture from any SF symbol at the desired points size, weight and scale. Plus, you&#8217;ll be able to colorize it and receive a fallback image if anything goes wrong in the process.</p>



<p>You can download the example Xojo project with the Module already created from <a href="https://www.dropbox.com/s/ndorw1mxu70wmww/SF%20Symbols-macOS.zip?dl=1">this link</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>QuickTip: Using SF Symbols in your macOS apps</title>
		<link>https://blog.xojo.com/2021/02/17/quicktip-using-sf-symbols-in-your-macos-apps/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 17 Feb 2021 21:05:54 +0000</pubDate>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8059</guid>

					<description><![CDATA[Since the publication of the post Quick Tip: SystemImage, more than 2,400 symbols at your disposal, some users raised the question about how to do the same on macOS. Continue reading to learn one possible technique.]]></description>
										<content:encoded><![CDATA[<p><em>See the updated post on this subject <a href="https://blog.xojo.com/2021/10/21/quicktip-using-sf-symbols-in-macos-revisited/">QuickTip: Using SF Symbols in macOS … revisited!</a></em></p>
<p>After the publication of <a href="https://blog.xojo.com/2020/12/17/quick-tip-systemimage-more-than-2400-symbols-at-your-disposal/">Quick Tip: SystemImage, more than 2,400 symbols at your disposal</a>, a user asked how to do the same on macOS. Continue reading to learn one way or check out <a href="https://blog.xojo.com/2021/10/21/quicktip-using-sf-symbols-in-macos-revisited/?preview_id=9397&amp;preview_nonce=276bb6a6cd&amp;preview=true">QuickTip: Using SF Symbols in macOS … revisited!</a> for a more flexible way to work with SF Symbols on macOS 11+.</p>
<p>The first step is to install the SF Pro font; download it from <a href="https://developer.apple.com/fonts">this link</a> and use the Font Book app to move it to your System fonts folder. In addition, you&#8217;ll find the SF Symbols <a href="https://developer.apple.com/sf-symbols">utility</a> valuable. It shows you the glyphs for the symbols in each font and the associated names.</p>
<p>On macOS we don&#8217;t have the <code><a href="https://documentation.xojo.com/api/graphics/picture.html#picture-systemimage">Picture.SystemImage</a></code> method to get and display these symbols, so what do we use? Well, they are simply glyphs from a font which means that we can get the Unicode codepoint for the symbols and use them in combination with the shared method <a href="https://documentation.xojo.com/api/text/encoding_text/textencoding.html#textencoding-chr">Encodings.utf8.chr</a>. The main problem is finding an easy way to get the codepoint equivalence for every symbol name found in the SF Symbols utility. To make this easier for everyone, <a href="https://www.dropbox.com/s/z4or8zagesreq2b/MacOSButtonCaptionGlyphAndColor.xojo_binary_project.zip?dl=1">download this Xojo example project</a> of a very basic class that does this for you. You&#8217;ll need to use the method <code>SFSymbol.Name</code> to provide the available names to get the String including the glyph.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-8060" src="https://blog.xojo.com/wp-content/uploads/2021/02/SF-Symbols-macOS-1024x972.png" alt="" width="500" height="475" srcset="https://blog.xojo.com/wp-content/uploads/2021/02/SF-Symbols-macOS-1024x972.png 1024w, https://blog.xojo.com/wp-content/uploads/2021/02/SF-Symbols-macOS-300x285.png 300w, https://blog.xojo.com/wp-content/uploads/2021/02/SF-Symbols-macOS-768x729.png 768w, https://blog.xojo.com/wp-content/uploads/2021/02/SF-Symbols-macOS.png 1424w" sizes="auto, (max-width: 500px) 100vw, 500px" /></p>
<p>In order for your app layout Controls to properly display the symbol you&#8217;ll also need to set the <code>FontName</code> for the control, for example, &#8220;SF Pro Display&#8221; or &#8220;SF Pro Compact&#8221;,  as well as set the <code>FontSize</code> property to the expected symbol size. You can use these symbols as the caption for buttons, the text drawn in any canvas or for any other item. In the image above you can see the SF Symbols applied to two standard Xojo buttons and also to the first column of the ListBox (displaying the associated Symbol name in the second column).</p>
<p>Using these symbols, as you already do with any of the other fonts, guarantees the maximum quality and sharpness at any size you choose. In addition, these also will react properly to Light Mode and Dark Mode.</p>
<p>Of course, you can make use of the SF Pro font in your apps under the license agreement and restrictions provided by Apple. In addition, macOS 11 includes a new API that is equivalent to the one found on iOS … I&#8217;ll show you how to use it in a future post.</p>
<h2>Bonus!</h2>
<p>Maybe you want to use these symbols as the icon displayed in the available Xojo buttons but you want to display them in different colors. There is a way to do it through declares! Take a look at the <code>ColorForButtonCaption</code> method under the <code>SymbolList</code> window.</p>
<p>Questions? Ask me on Twitter <a href="https://twitter.com/xojoes">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary">Xojo Forum</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Quick Tip: Listing System Fonts on iOS</title>
		<link>https://blog.xojo.com/2021/01/14/quick-tip-listing-system-fonts-on-ios/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Thu, 14 Jan 2021 19:23:14 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=7973</guid>

					<description><![CDATA[Let's learn how your iOS app can offer the user the option to select the font they want from a list (or any other UI control of your choice) just like in Desktop apps.]]></description>
										<content:encoded><![CDATA[<p>Xojo 2020r2 introduced the new <a href="https://documentation.xojo.com/api/graphics/font.html"><strong>Font</strong></a> class to deal with any font that you want to use in your iOS apps. The Constructor method for the class receives the font name (the PostScript one) and the font size.<span id="more-7973"></span></p>
<p>You can find fonts on websites like&nbsp;<a href="http://iosfonts.com">iosfonts.com.</a>&nbsp;But wouldn&#8217;t it be great to access these directly from code? Let&#8217;s learn how your iOS app can offer the user the option to select the font they want from a list (or any other UI control of your choice) just like in Desktop apps.</p>
<p>To do this, use a little helper class included in the iOS example project (<a href="http://bit.ly/2LdWaVJ" data-wplink-edit="true">download from this link)</a>. This class uses the <a href="https://blog.xojo.com/2016/06/08/design-patterns-in-xojo-singleton/">Singleton pattern,</a>&nbsp;and if a font is not installed on the iOS version of the device running the app, then it fallbacks to the default font used in iOS.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-7974 size-full" src="https://blog.xojo.com/wp-content/uploads/2021/01/iOSSystemFonts.png" alt="" width="442" height="873" srcset="https://blog.xojo.com/wp-content/uploads/2021/01/iOSSystemFonts.png 442w, https://blog.xojo.com/wp-content/uploads/2021/01/iOSSystemFonts-152x300.png 152w" sizes="auto, (max-width: 442px) 100vw, 442px" /></p>
<p>With this class at hand, you only need to call the shared method:</p>
<pre>iOSSystemFonts.Fonts As String()</pre>
<p>In order to receive an Array of Strings containing the name of the fonts. The class also provides the following shared methods:</p>
<pre>iOSSystemFonts.FontCount As Integer<br>
iOSSystemFonts.LastFontIndex As Integer<br>
iOSSystemFonts.FontAt(Index As Integer, Optional size As Integer = 0) As Font</pre>


<p>To try this out for yourself, <a href="http://bit.ly/2LdWaVJ">download and run the sample project</a>.</p>



<p>Questions? Ask me on Twitter <a href="https://twitter.com/xojoes">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary">Xojo Forum</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Xojo&#8217;s PDFDocument Class, Beyond the Standard 14 and More</title>
		<link>https://blog.xojo.com/2020/08/27/xojos-pdfdocument-class-beyond-the-standard-14-and-more/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Thu, 27 Aug 2020 11:12:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=7317</guid>

					<description><![CDATA[One of the trickier things when dealing with PDF document creation is typography. By default, the PDF typography handling in Xojo's PDFDocument class includes the "standard 14", 14 typefaces you can use freely without requiring them to be included as part of the document itself. That guarantees a very important thing: any user can open and view that PDF document as it was created, without the text suffering from typography substitution, style lost, variations in kerning and tracking, etc. The standard 14 include Times, Courier, Helvetica, Symbol and Zapf Dingbats.]]></description>
										<content:encoded><![CDATA[<p>One of the trickier things when dealing with PDF document creation is typography. By default, the PDF typography handling in Xojo&#8217;s <a href="https://documentation.xojo.com/api/pdf/pdfdocument.html">PDFDocument</a> class includes the &#8220;<a href="https://en.wikipedia.org/wiki/PDF#Standard_Type_1_Fonts_(Standard_14_Fonts)">standard 14</a>&#8220;, 14 typefaces you can use freely without requiring them to be included as part of the document itself. This guarantees a very important thing: any user can open and view that PDF document as it was created, without the text suffering from typography substitution, style lost, variations in kerning and tracking, etc. The standard 14 include&nbsp;Times,&nbsp;Courier,&nbsp;Helvetica,&nbsp;Symbol&nbsp;and Zapf Dingbats.<span id="more-7317"></span></p>
<p>In order to simplify their use, we included an Enumeration as part of the PDFDocument Class. So, if for example you want to use the <code>Times-Bold</code> variant, then you only need to use these two lines of code:</p>
<pre>g.FontName = PDFDocument.StandardFontNames.Times
g.Bold = True</pre>
<p>This also speeds up the creation of your PDFs &#8211; Bonus!</p>
<h2>Beyond the Standard 14</h2>
<p>But you may need something beyond the standard 14 and that is where things can start to get more complicated. In order to be able to “draw” these other fonts in vectorial representation as part of your document, the PDF standard needs to know in advance lots of details of the typography itself: glyphs width, maximum and minimum kerning values, if they include Italic or Bold variations, etc. And it can get even more complicated when you need to support several fonts.&nbsp;That means that the PDFDocument class needs to go inside and explore every one of the fonts you may use in your document so they are properly rendered, and that means inspecting a LOT of data!</p>
<p>In oder to alleviate this very consuming process, the PDFDocument class uses several techniques to speed things up when it comes to the many fonts you have installed. For example, one of the more obvious of these is using a delayed font exploration …&nbsp;so it only takes place when you are going to use a specific font the first time, caching all the required information for later accesses. In addition, it pre-caches the name of all the fonts you have installed in your OS Fonts folder so it can “find&#8221; those fonts faster once you’re ready to use one of them.</p>
<p>These two techniques, in addition to others, ensure that the initial PDFDocument creation and text drawing is as fast as possible for the “reasonable” (or even for the not so “reasonable”) amount of fonts you may have installed in your computer.</p>
<p>An important difference when using fonts other than the standard 14, is that nobody ensures that the user viewing your PDF document will have that same fonts installed on their computer too (including even variants of the same font) and that can lead to a rendering text &#8220;disaster”!</p>
<p>In order to guarantee that your PDF texts will render correctly, no matter how many fonts you are using, all the required font data is included as part of the PDF document itself (it has embedded the font data). For the small price of including the font data as part of the document, regardless of if the user has any of the fonts installed on their computer, the text of the PDF document will be rendered however you set it during its creation.</p>
<p>No matter how many times you are going to use the same font in your document, the reference (and, thus, the font data) will be included only once.</p>
<h2>Speeding Things Up</h2>
<p>In addition, it may be the case that you are interested in working only with a subset of the fonts you have installed on your drive (or apart from these, for example, only the ones included as part of your own app or solution). If that is the case, then you can use the <code>PDFDocument.AddFonts</code> method passing along a FolderItem parameter pointing to the folder containing the font files. Just make sure to use this method before using any of the fonts! Also, this will speed up the font inspection process even more because the PDF will look for the required data only among the files added by the AddFonts method. You may use the <code>PDFDocument.AddFonts</code> pointing to different font sets as many times as you may need.</p>
<p>For example, let&#8217;s say we have a folder on the desktop with a total of 20 font files inside; so the following snippet of code will create a “Font catalog” PDF document whose contents are a total of 20 lines composed with a fixed sample text followed by the font name:</p>
<pre>Var f As FolderItem = SpecialFolder.Desktop.Child("Fonts Catalog")

PDFDocument.AddFonts(f)

Var fName As String
Var pdfDoc As New PDFDocument
Var g As Graphics = pdfDoc.Graphics
Var offset As Integer = 20

Var textSample As String = "Text Sample with Font: "

For n As Integer = 0 To 20
  
  fName = f.ChildAt(n).Name.NthField(".", 1)
  
  g.FontName = fName
  g.FontSize = 10
  g.DrawText(textSample + fName, 20, offset)
  
  offset = offset + 10 + g.FontAscent
  
Next

Var target As FolderItem = SpecialFolder.Desktop.Child("FontSample.pdf")

pdfDoc.Save(target)

target.Open</pre>
<p>In this case, the following screenshot shows the resulting PDF document:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-7319" src="https://blog.xojo.com/wp-content/uploads/2020/08/FontsCatalog.png" alt="" width="816" height="687" srcset="https://blog.xojo.com/wp-content/uploads/2020/08/FontsCatalog.png 816w, https://blog.xojo.com/wp-content/uploads/2020/08/FontsCatalog-300x253.png 300w, https://blog.xojo.com/wp-content/uploads/2020/08/FontsCatalog-768x647.png 768w" sizes="auto, (max-width: 816px) 100vw, 816px" /></p>
<p>The total size of the PDF document is a mere 700 KB on disk, with the guarantee that it will be correctly displayed by anyone you send it because the font data is embedded in the document itself! If you are curious, you can download the PDF document itself from <a href="https://drive.google.com/file/d/11QdVmPEZYhpJ4XlNCeXZhEUL8rTSIPcr/view?usp=sharing">this link.</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>JetBrains Mono Programmer Font</title>
		<link>https://blog.xojo.com/2020/01/30/jetbrains-mono-programmer-font/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 30 Jan 2020 10:00:00 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Font]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6528</guid>

					<description><![CDATA[There's a new programming font that was just released and since I like to look at programming fonts, I thought I'd give this one a try with Xojo.]]></description>
										<content:encoded><![CDATA[
<p>There&#8217;s a new programming font that was just released and since <a href="https://blog.xojo.com/2013/11/26/code-editor-fonts/">I like to look at programming fonts</a>, I thought I&#8217;d give this one a try with Xojo.</p>



<p>The font is called JetBrains Mono (from JetBrains, makers of a Java IDE). Be sure to check out the web site as it shows off many of the cool features of the font:</p>



<p><a href="https://www.jetbrains.com/lp/mono/">https://www.jetbrains.com/lp/mono/</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="666" src="https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-1024x666.png" alt="" class="wp-image-6529" srcset="https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-1024x666.png 1024w, https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-300x195.png 300w, https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-768x500.png 768w, https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-1536x999.png 1536w, https://blog.xojo.com/wp-content/uploads/2020/01/2020-01-24_11-46-47-2048x1332.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption>Xojo Code Editor using JetBrains Mono Code Font</figcaption></figure>



<p>Above you can see how the Xojo IDE Code Editor looks with this font. I&#8217;ve only just started using it but so far I find it a bit easier to read than Source Code Pro, which is what I have been using.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Using Google Fonts in Your Web Apps</title>
		<link>https://blog.xojo.com/2017/08/23/using-google-fonts-in-your-web-apps/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 23 Aug 2017 10:00:48 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">http://blog.xojo.com/?p=2860</guid>

					<description><![CDATA[Here&#8217;s a quick and free tip I found on the Xojo Forums a while back! You can use Google Fonts in your web app to make&#8230;]]></description>
										<content:encoded><![CDATA[<p>Here&#8217;s a quick and free tip I found on the Xojo Forums a while back! You can use Google Fonts in your web app to make it look snazier. There are hundreds of Google Fonts available to choose from in all kinds of styles. Read on to learn how:</p>
<p><span id="more-2860"></span></p>
<p>You can see what is available for Google Fonts here:</p>
<p><a href="https://fonts.google.com">https://fonts.google.com</a></p>
<p>Here are the <a href="http://developer.xojo.com/using-google-fonts">steps to use a Google Font</a> in your web app.</p>
<ol>
<li>Click on the name of the font to go to its page. As an example font to try, select the font called &#8220;Orbitron&#8221;.</li>
<li>On the Orbitron page, click &#8220;SELECT THIS FONT&#8221; in the top right.</li>
<li>This adds a banner at the bottom of the page that says &#8220;1 Family Selected&#8221;. Click the banner to display the full details. Make sure &#8220;Standard&#8221; is selected and copy the HTML text. For Orbitron it looks like this:
<ol>
<li>
<pre>&lt;link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet"&gt;</pre>
</li>
</ol>
</li>
<li>In your Xojo web project select the App and then click the &#8220;pencil&#8221; icon next to the HTMLHeader property to show the editor. Paste the text you copied from above into the property. Leave the editor open as you have more HTML to add.</li>
<li>Go back to the Orbitron page and copy the text in the &#8220;Specify in CSS&#8221; section. For Orbitron it looks like this:
<ol>
<li>
<pre>font-family: 'Orbitron', sans-serif;</pre>
</li>
</ol>
</li>
<li>Back in Xojo, add &lt;style&gt;&lt;/style&gt; tags to the editor.</li>
<li>In between the style tags, add a period followed by the name of the Google Font and two curly brackets
<ol>
<li>
<pre>&lt;style&gt;.Orbitron {}&lt;/style&gt;</pre>
</li>
</ol>
</li>
<li>In between the curly brackets add the code you copied from above.</li>
<li>In the end you&#8217;ll have text in the editor that looks like this:
<ol>
<li>
<pre>&lt;link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet"&gt;</pre>
</li>
<li>
<pre>&lt;style&gt;.Orbitron {font-family: 'Orbitron', sans-serif;}&lt;/style&gt;</pre>
</li>
</ol>
</li>
<li>Go back to Xojo can create a new Web Style. Make sure its name matches the name of the Google Font This is case-sensitive so make sure it matches exactly. For Orbitron, the Web Style should be called &#8220;Orbitron&#8221;.</li>
<li>On WebPage1, add a Label with some text and change its Style property to Orbitron.</li>
<li>Run your project. The text should appear using the Google Font.</li>
</ol>
<p>Special thanks to Michel Bujardet, Matthew Combatti and others for pointing out this technique in these forum conversations: <a href="https://forum.xojo.com/10243-google-fonts/0">Google Fonts</a>, <a href="https://forum.xojo.com/22640-styles/0">CSS Styles</a>.</p>
<p><small>References: <a href="http://developer.xojo.com/using-google-fonts">Xojo Dev Center</a>, <a href="https://fonts.google.com/">Google Fonts</a>, <a href="https://forum.xojo.com/10243-google-fonts/0">Xojo Forum</a></small></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Code Editor Fonts</title>
		<link>https://blog.xojo.com/2013/11/26/code-editor-fonts/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 26 Nov 2013 00:00:00 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Code Editor]]></category>
		<category><![CDATA[Font]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2013/11/26/code-editor-fonts/</guid>

					<description><![CDATA[Code Editor Fonts]]></description>
										<content:encoded><![CDATA[<p>There are a wide variety of fonts that work great with the Xojo code editor. All are much better choices than using System or Courier! For best results, you are going to want to use a monospaced font. Read on for some of my favorites.</p>
<p><span id="more-73"></span><br />
<strong>Monaco</strong><br />
This font is installed by default on MacOS. It is big and very easy to read.<br />
<a href="http://www.gringod.com/2006/11/01/new-version-of-monaco-font/">http://www.gringod.com/2006/11/01/new-version-of-monaco-font/</a></p>
<p><strong>Menlo</strong><br />
Also included by default on MacOS.<br />
<a href="http://en.wikipedia.org/wiki/Menlo_(typeface)">http://en.wikipedia.org/wiki/Menlo_(typeface)</a></p>
<p><strong>Source Code Pro</strong><br />
Adobe just released this font in 2012 or so and I really like it. I have been using as my default font since I first found out about it. The screen shot below shows how it looks in Xojo on Mac.<br />
<img loading="lazy" decoding="async" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" src="https://blog.xojo.com/wp-content/uploads/2013/11/sourcecodepro-thumb-400x291-213.pngt1466486449161ampwidth400ampheight291" sizes="auto, (max-width: 400px) 100vw, 400px" alt="SourceCodePro.png" width="400" height="291" /><br />
<a href="https://github.com/adobe-fonts/source-code-pro">https://github.com/adobe-fonts/source-code-pro</a></p>
<p><strong>Inconsolata</strong><br />
This is what I used until I switched to Source Code Pro. It is a little smaller than other fonts at the same point size.<br />
<a href="http://levien.com/type/myfonts/inconsolata.html">http://levien.com/type/myfonts/inconsolata.html</a></p>
<p><strong style="line-height: 1.62;">ProFont</strong><br />
This is the first alternative font I used. I think the others mentioned here are nicer.<br />
<a href="http://www.tobias-jung.de/seekingprofont/">http://www.tobias-jung.de/seekingprofont/</a></p>
<p><strong>What do you use?</strong><br />
There are dozens of other great programming fonts. What is your favorite? Let us know on Twitter (<a href="https://twitter.com/xojo">@xojo</a>).<br />
<em>Note: A version of this post was previously published in Oct 2012.</em></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
