I am trying to achieve following things:
ComputeSubset method of GlyphTypeface class in WPFCreateFontPackage in FontSub.dllc:\windows\fonts, and I am able to type all characters in that font whereas I was expecting it will only show characters which I selected.I've used both methods you mention, the first one is far easier. Here's the code I use:
Imports System.Text.Encoding
Imports System.Collections
Imports System.Windows.Media
Public Class FontManager
Sub New()
CreateSubSet("my baloney has a first name", New Uri("C:\Windows\Fonts\impact.ttf"))
End Sub
Public Sub CreateSubSet(sourceText As String, fontURI As Uri)
Dim glyphTypeface As GlyphTypeface = New GlyphTypeface(fontURI)
Dim Index As Generic.ICollection(Of UShort)
Index = New Generic.List(Of UShort)
Dim sourceTextBytes As Byte() = Unicode.GetBytes(sourceText)
Dim sourceTextChars As Char() = Unicode.GetChars(sourceTextBytes)
Dim sourceTextCharVal As Integer
Dim glyphIndex As Integer
For sourceTextCharPos = 0 To UBound(sourceTextChars)
sourceTextCharVal = AscW(sourceTextChars(sourceTextCharPos))
glyphIndex = glyphTypeface.CharacterToGlyphMap(sourceTextCharVal)
Index.Add(glyphIndex)
Next
Dim filebytes() As Byte = glyphTypeface.ComputeSubset(Index)
Using fileStream As New System.IO.FileStream("C:\Users\Me\Documents\impact-subset.ttf", System.IO.FileMode.Create)
fileStream.Write(filebytes, 0, filebytes.Length)
End Using
End Sub
End Class
Of course for sourceText, you can just send in unique characters if you want.
The link gilamesh mentions is a great place for learning about TTF fonts. The other reference which I've found to be invaluable is http://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html
If you are interested in learning the TTF specification, you can refer to the Microsoft TrueType specification v1.66. see http://www.microsoft.com/typography/SpecificationsOverview.mspx.
The font table you would be interested in is the CMAP table which specifies the mapping of the character code to the glyph index .
However I think referring to the specification is an overkill if all you want to do is to verify that the subsetted TTF font contains the correct characters.
I recommend using a tool to dump out the contents of font into a readable format instead. There is a tool called TTX which can output a XML representation of a font table for a given Font. see http://www.letterror.com/code/ttx/index.html
Once you got TTX running, you can run the command "ttx.exe -tcmap MyFont.ttf" and it should output a file "MyFont.ttx". Open it in a text editor and it should show you all the character code it found in the font
Update for Ujjwal questions:
I have no experience in using .NET to handle fonts; sorry I cannot help you with your .NETs questions
The Apple link Otaku provided is more readable than the Microsoft specs; just be aware that the Apple and Microsoft specs for the TTF format are slightly different in certain aspects.
Generally I would say the size of the font depends on how complex the retained character glyphs are and also whether the hinting data is preserved or not. From the fonts I have seen, these data makes up the bulk of TTF font. (Actually embedded bitmaps takes up more space but based on the size of the font you mentioned, I bet it does not contain embedded bitmaps)
Not sure if this will be useful, but if you cannot change the name of the font using .NET you might be interested looking up a tool called FontForge http://fontforge.sourceforge.net/. I have not really used it myself but I believe it should allow you to change the font name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With