How to test that a string can be represented by a font

My app creates a PDF file in a user-specified font.  If a particular string 
contains characters that cannot be represented in that font, the app needs 
to know.  What it then does is to throw the string into an RTF control and 
parses the TextRTF result to see what fonts are used.  It can then switch 
the fonts of the PDF output for the text, or text segments, in line with 
what the RTF control has specified.

However, to do this for every string is quite intensive

The question is how to know if the string can be displayed in its entirety 
by the currently user-specified font so that the RTF logic is only applied 
if it cannot.

This is relatively easy for systems with English codepages and standard 
fonts,  I have created a function "WillFontDisplayString (FontName, 
TextString)" which sets the font of a label to the required text, sets the 
caption equal to the text, and checks the caption against the text.  If they 
are now not equal (because "?" has been substituted for some characters), 
the app knows that it needs to apply the RTF parsing logic.  If the captions 
are equal, we conclude that the font was OK with that string.

The problem comes when Windows does automatic font substitution.  If I 
change the codepage to, say, "Chinese (simplified)" and reboot, then things 
break down.

In this situation, the label test fails because Windows will now place the 
Chinese characters in the label via font substitution (even though the Times 
New Roman font assigned to the label does not support Chinese), so now the 
caption matches the string and the app does not determine that Chinese does 
not fit Times New Roman.

So what I need is a fast and reliable method for the function 
"WillFontDisplayString (FontName, TextString)" which will work universally.

I have Googled for days, but I can find no way of determining that font 
substitution occurred, nor anyway of suppressing font substitution.  It 
seems that the label trick is doomed.   Therefore, I have also searched for 
code snippets that might be equivalent to "WillFontDisplayString", but so 
far no luck.

Does anyone have any ideas?

Thanks in advance,
Nigel 

0
Nigel
9/10/2010 1:56:38 PM
vb.general.discussion 1016 articles. 0 followers. Follow

6 Replies
1732 Views

Similar Articles

[PageSpeed] 41

Nigel Bufton <nigel@bufton.org> schrieb im Beitrag
<#GBFIAPULHA.564@TK2MSFTNGP04.phx.gbl>...
> This is relatively easy for systems with English codepages and standard 
> fonts,  I have created a function "WillFontDisplayString (FontName, 
> TextString)" which sets the font of a label to the required text, sets
the 
> caption equal to the text, and checks the caption against the text.  If
they 
> are now not equal (because "?" has been substituted for some characters),

> the app knows that it needs to apply the RTF parsing logic.  If the
captions 
> are equal, we conclude that the font was OK with that string.

The "?" doesn't mean that there is no glyph for the character in the font
used but only that there is no representation for the Unicode character in
the current character set/code page. If there is no glyph for a specific
Unicode character in a font the default glyph (usually a square box) is
displayed instead. This could be checked by some kind of OCR only.

> So what I need is a fast and reliable method for the function 
> "WillFontDisplayString (FontName, TextString)" which will work
universally.

Pass the string to GetGlyphIndices() (Win >= Win 2K only!) with the
GGI_MARK_NONEXISTING_GLYPHS flag set. In the glyph indices array filled by
this procedure any value 0xFFFF means that in the font used there is no
glyph available for the character.
This should be reliable. To make your code fast you should implement some
sort of caching (i.e. a list of characters which already have been checked,
or the like).

-- 
Thorsten Albers

albers (a) uni-freiburg.de

0
Thorsten
9/10/2010 2:44:18 PM
See GetFontUnicodeRanges(Win2000+), or GetTextCharsetInfo(Win95+).

GetFontUnicodeRanges Function:
http://msdn.microsoft.com/en-us/library/dd144887%28VS.85%29.aspx

GetTextCharsetInfo Function:
http://msdn.microsoft.com/en-us/library/dd318126%28VS.85%29.aspx


0
Nobody
9/10/2010 5:58:20 PM
Nobody <nobody@nobody.com> schrieb im Beitrag
<i6drjs$6g5$1@speranza.aioe.org>...
> See GetFontUnicodeRanges(Win2000+), or GetTextCharsetInfo(Win95+).
> 
> GetFontUnicodeRanges Function:
> http://msdn.microsoft.com/en-us/library/dd144887%28VS.85%29.aspx
> 
> GetTextCharsetInfo Function:
> http://msdn.microsoft.com/en-us/library/dd318126%28VS.85%29.aspx

It is very important to remark that even if a certain Unicode range is
supported by a font this does in no case mean that the font provides a
glyph for any (assigned) character of that range.

-- 
Thorsten Albers

albers (a) uni-freiburg.de

0
Thorsten
9/10/2010 10:01:32 PM
"Thorsten Albers" <albersSKIP@THISuni-freiburg.de> wrote in message
news:01cb50f6$9fecbc20$8901a8c0@thalk8s8x...
> Nigel Bufton <nigel@bufton.org> schrieb im Beitrag
>> So what I need is a fast and reliable method for the function
>> "WillFontDisplayString (FontName, TextString)" which will work
> universally.
>
> Pass the string to GetGlyphIndices() (Win >= Win 2K only!) with the
> GGI_MARK_NONEXISTING_GLYPHS flag set. In the glyph indices array filled by
> this procedure any value 0xFFFF means that in the font used there is no
> glyph available for the character.
> This should be reliable. To make your code fast you should implement some
> sort of caching (i.e. a list of characters which already have been
> checked,
> or the like).
>
> -- 
> Thorsten Albers
>
> albers (a) uni-freiburg.de
>

Could you provide example code for declaring and calling GetGlyphIndices
please.  It is not in my API guide.

Thanks,
Nigel 

0
Nigel
9/11/2010 11:54:10 AM
Nigel Bufton <nigel@bufton.org> schrieb im Beitrag
<OHBPNgaULHA.5944@TK2MSFTNGP06.phx.gbl>...
> Could you provide example code for declaring and calling GetGlyphIndices
> please.  It is not in my API guide.

Private Declare Function GetGlyphIndices _
  Lib "gdi32" _
  Alias "GetGlyphIndicesW" _
  ( _
    ByVal hDC As Long, _
    ByVal sChars As Long, _
    ByVal lCharCount As Long, _
    ByRef paGlyphIndices As Any, _
    ByVal lFlags As Long, _
  ) As Long

Private Const GGI_MARK_NONEXISTING_GLYPHS As Long = &H1
Private Const GDI_ERROR As Long = &HFFFFFFFF
Private Const INVALIDGLYPHINDEX As Integer = &HFFFF


Dim sMyString As String
Dim aiGlyphIndex() As Integer
Dim lNumIndices As Long


sMyString$ = "abc"
ReDim aiGlyphIndex(0 To (Len(sMyString$) - 1)) As Integer

Err.Clear
lNumIndices& = GetGlyphIndices(Me.hDC, _
  StrPtr(sMyString$), Len(sMyString$), _
  aiGlyphIndex(0), _
  GGI_MARK_NONEXISTING_GLYPHS)
If lNumIndices& = GDI_ERROR Then
  MsgBox "Last DLL error: " & Err.LastDLLError
ElseIf lNumIndices& < 1 Then
  MsgBox "Number of indices = " & lNumIndices& & "!"
Else

 ' Check aiGlyphIndex() entries on 
 ' INVALIDGLYPHINDEX

End If


This I have written 'on the fly', i.e. online and not in VB...

Be aware of the fact that Unicode codepoints of certain Unicode ranges -
the so-called surrogates - consist of 2 16 bit codes instead of 1 (= 2 VB
string characters instead of 1).

-- 
Thorsten Albers

albers (a) uni-freiburg.de

0
Thorsten
9/11/2010 12:27:00 PM

"Thorsten Albers" <albersSKIP@THISuni-freiburg.de> wrote in message 
news:01cb51ac$98f2e0f0$8901a8c0@thalk8s8x...
> Nigel Bufton <nigel@bufton.org> schrieb im Beitrag
> <OHBPNgaULHA.5944@TK2MSFTNGP06.phx.gbl>...
>> Could you provide example code for declaring and calling GetGlyphIndices
>> please.  It is not in my API guide.
>
> Private Declare Function GetGlyphIndices _
>  Lib "gdi32" _
>  Alias "GetGlyphIndicesW" _
>  ( _
>    ByVal hDC As Long, _
>    ByVal sChars As Long, _
>    ByVal lCharCount As Long, _
>    ByRef paGlyphIndices As Any, _
>    ByVal lFlags As Long, _
>  ) As Long
>
> Private Const GGI_MARK_NONEXISTING_GLYPHS As Long = &H1
> Private Const GDI_ERROR As Long = &HFFFFFFFF
> Private Const INVALIDGLYPHINDEX As Integer = &HFFFF
>
>
> Dim sMyString As String
> Dim aiGlyphIndex() As Integer
> Dim lNumIndices As Long
>
>
> sMyString$ = "abc"
> ReDim aiGlyphIndex(0 To (Len(sMyString$) - 1)) As Integer
>
> Err.Clear
> lNumIndices& = GetGlyphIndices(Me.hDC, _
>  StrPtr(sMyString$), Len(sMyString$), _
>  aiGlyphIndex(0), _
>  GGI_MARK_NONEXISTING_GLYPHS)
> If lNumIndices& = GDI_ERROR Then
>  MsgBox "Last DLL error: " & Err.LastDLLError
> ElseIf lNumIndices& < 1 Then
>  MsgBox "Number of indices = " & lNumIndices& & "!"
> Else
>
> ' Check aiGlyphIndex() entries on
> ' INVALIDGLYPHINDEX
>
> End If
>
>
> This I have written 'on the fly', i.e. online and not in VB...
>
> Be aware of the fact that Unicode codepoints of certain Unicode ranges -
> the so-called surrogates - consist of 2 16 bit codes instead of 1 (= 2 VB
> string characters instead of 1).
>
> -- 
> Thorsten Albers
>
> albers (a) uni-freiburg.de

Thanks - it works great.

Nigel
> 
0
Nigel
9/11/2010 2:08:22 PM
Reply:

Similar Artilces:

Can i hide the adress where my mail is sent from
Hi, I'm sending mail using a exch2003 and outlook 2003 version and know i can hide the adresses where i send mail to but can i hide (my address) where the mail is coming from so if i send any of you a mail you won't see its from me but will see the body of the mail. Is this possible? Have you ever received any spam email with blank sender? It's possible, but not using Exchange. Now, most email server will drop emails with blank sender. Exchange 2k3 SP2 will use Sender ID filtering to check whether you have the rights to send email on behalf of the email domain in your sen...

Can't Send/Receive at all
I have been using Outlook 2003 for over a year without problem, and now when I open the application the automatic send/receive doesn't execute. Also whenever I click the send/receive button nothing happens. And when I go to Tools>Options>Mail Setup and click the send/receive button, no config window launches like it should. Again nothing at all happens. I have deleted the profile and recreated it, but to no avail. I have also done a "Detect and Repair" under the Help menu which also didn't work. Help please, Kent It sounds like you need to uninstall and then rei...

Display fields from multiple tables in a form that I can enter dat
I need to create a form that I can use to enter and manage data from/for my HomeRepairs table. But I would also like the form to display information (that I won't need to edit) from other tables (like Phone Number and Address data that's stored in my Constituents table). The common field in all the tables is the ConID (Constituent ID). I've created a query that pulls (almost) all the information I want displayed, but when I create the form based on it, I can't enter any data. How can I create a form with fields from multiple tables that I can actually USE as a for...

How can you convert a Publisher File to hi-res jpeg or bmp file
I don't want to use clipboard and paste as I lose hi res. I have produced a newsletter and want to hand it over to others to print. They do not have Microsoft Publisher so I want to be able to give them it in a format they can look at and print. A small child turns to Ed, and exclaims: "Look! Look! A post from Tim OD <Tim OD@discussions.microsoft.com>!"... > They do not have Microsoft Publisher so I want to be able to > give them it in a format they can look at and print. Then you don't save as an image file, you save as a PDF file. See http://www.primopdf.co...

about the string literal pool
Hi! Does all string literal be stored in the string literal pool. I mean is there any limitation or once a string literal is declared it will be put in the pool and stay there until the program stops. //Tony Hello, > Does all string literal be stored in the string literal pool. I mean is > there any limitation or once a string literal is declared it will be put > in the pool and stay there until the program stops. Do you see a reason for doing otherwise ? Not me... It's good to generally question everything but what made you think that perhaps it co...

Can you import data into specific cells of an Excel spreadsheet?
I've created a template and want to import data into specific cells so that my charts can automatically display. Is this possible? Yes - presumming that both files are Excel, open both, go to Window on your drop down menu and select Arrange and click on tile. If all the data you'd like to import is consecutive, you can highlight the range, right click and select copy, then go to your template, right click in the cell you'd like to bring the data into, select paste special and then paste link. If the cells aren't consecutive you can import each cell individually using t...

How can I change a cell value based on another cells color?
I have many different values on a large spreadsheet. I am wondering if there is a way to change a cell value to match another cell value based on the second cells color? For example, I would need to change cell A1 to a value of 10 so it matches cell A2's value of 10, because cell A2 is highlighted in green. I am not familiar with macros, is this something that would require a macro? There's no built-in feature that will change a cell's value based on the colour of another cell. You would need to use code to accomplish this. Chip Pearson has information on using colours in ...

Can't download newsgroups in WLM
I apologize for reposting this. I first posted this question as a reply to another post because I couldn't find a way to post a new post. Running windows 7 on an Acer laptop, 3 GB of RAM, and just set up my WLM mail to be readable in another part of the country, but I can't download or create a list of MS newsgroups without getting an error message that there's something wrong with my WL mail account but I'm signed onto WLM and WL just fine. Paul C. Can you capture the exact error message? Right-click on your error message, copy, then paste it into a reply =...

Cant send a email but I can receive them????
This is my error message??? Can you please help??? The connection to the server has failed. Subject 'test4', Account: 'hair', Server: 'mail.exquisitereflections.info', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 10013, Error Number: 0x800CCC0E Did it ever work? Exquisitereflections.info obviously is not your ISP. As such, your home ISP will block your use of any port 25 SMTP server other=20 than their own.=20 For an explanation of this anti-spamming policy, see http://www.postcastserver.com/help/Port_25_Blocking.aspx To send from home, you...

How do I get the email server name for the yahoo.com or how can I. #2
-- David Peters If you have a paid yahoo e-mail account you should be able to get the server name from yahoo.com. They have instructions on how to set it up for their paying customers but it is not available to non-paying customers. Robert Findlay Partner Technical Lead -- BizApps Microsoft Technical Support for Platforms and Business Applications ...

Can one see a snapshot of net worth in money for past periods
I thought any financial management program would have this feature ... but could not find this anywhere. What is needed: Money shows me the total of my assets in different accounts. What if I want to find out what was my total assets 1 month ago , 2 months ago and so on. Once I update the accounts with the latest info, Money also updates its total but does not save it anywhere. If this feature is not included in MS Money - is there any way to achieve this using indirect means eg. through a report. Solution greatly appreciated as I am badly stuck on some decisions without it. I will have to cre...

Can Excel fill in numbers to equal a predetermined total?
Hi! I'm fairly new to Excel and I'm not sure if it's possible to do what I want to do but here it is... In column A, I have a person's name, then five blank cells, then in column H, I have a 28 (total). Is it possible to write a formula to have "defined names" (I already defined the names DAY=8, HALF=4) randomly filled into the blank cells in the row to add up to the "total"? Another question...Is it possibly to define a name to equal one thing in a row but something else in a column? Basically what I'm trying to do is make a self-filling sc...

Class Diagram -> no java data type? How can I manually create data type?
in Class Diagram template There is no java data type. How can I manually create data type? Thank you Sean Sean, I'm afraid you will have to create your own Java Datatype for Java. The only thing that comes close is C# Data types. "Sean Kim" wrote: > in Class Diagram template > > There is no java data type. > How can I manually create data type? > > > Thank you > > Sean > How do we create out own types, like int, Character, Map, String, etc? Could we have some info on that please! Regards, Yazad Khambata "Russ_from_Alabama&...

Can use VSTO to reduce the size of a file?
I have a really large spreadsheet that is saved in a sharepoint location but takes about five minutes to load. Would it make any difference if I recreate the file using VSTO? Thanks in advance ...

Can't login after applying Rollup 4
Hi, Has anyone else faced this? It's telling me it's an invalid domain login (friendly), or the GUID of the server can't be found in the forest. Yet Rollup 3 works fine. Thanks Chris ...

Can no longer add select pictures to add in PUBLISHER 2003
I can no longer add pictures to a publishing document also I can no longer save a publishing document - I get a don't have enough memory message. How big is that file? -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "vc826" <vc826@discussions.microsoft.com> wrote in message news:337835A2-EB99-4160-BE31-60C45A84C298@microsoft.com... >I can no longer add pictures to a publishing document also I can no longer > save a publishing document - I get a don't have enough memory message. every file I can...

euro font substitution
The euro has been in business for ten years now. It is now part of every professional font, including a hundred or two installed on my system. Today Publisher 2003 tells me it is not part of the Arial font (!) and that I should indicate a substitute. But Publisher rejects all proposals and leaves me with the wretched Times Roman version. Could someone tell me what's up and how to fix it? The euro symbol works for me in Arial and Publisher 2003... Hold alt+0128. Did you open >Insert >Symbol, scroll down to currency symbols? Support for the new Euro currency symbol in Office htt...

how can I run a macro when I open a workbook?
.... hi. put your macro in the workbooks on open event. when the workbooks is opened, the macro runs. :o >-----Original Message----- >.... >. > name it auto_open filo666 wrote: > > ... -- Dave Peterson ...

Can I add a scissors line down a page (in between two pages)?
Hi, Is it possible to add a scissors line down a page? Thanks You mean like cutting out a coupon? BorderArt, draw a box, lines, more lines, borderart. You can draw a line and make it dashed... -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "9thbit" <9thbit@discussions.microsoft.com> wrote in message news:B7FF49C3-B9AF-4A9F-AFFA-15BED6E9672B@microsoft.com... > Hi, > Is it possible to add a scissors line down a page? > > Thanks ...

Counting the frequency of a text string
I've inherited some data to work with that I'm not sure how to approach. Basically, multiple answers are contained within a cell. I need to extract a sum of each individual answer. The data looks like this: Special Education Students;#Economically Disadvantaged Students;#Minority Students;#Regular Classroom Students;#Gifted and Talented Students Special Education Students;#Economically Disadvantaged Students;#Minority Students Special Education Students;#Economically Disadvantaged Students;#Minority Students;#Regular Classroom Students;#Gifted and Talented Students Special Edu...

Querying against two data sources/connection strings
I have a text file I'd like to access as if it were a database. It has prices for various commodities. The name of the file changes every day. I also have a SQL Server, which has a list of the commodities we're interested in. I would like to access the text file via a connection string, and then join it on the data in our SQL server. Is there a way to do this? It appears queries can have only one connection? Maury keep all your data in SQL Server and then it's easy to join between SQL data and SQL data "Maury Markowitz" <MauryMarkowitz@discussions.microsoft.c...

can I put a multiple worksheets within a worksheet(s) in a spreads
Example: If I have a spreadsheet named Linda, and it has 3 worksheets in it, named Julie, Bob, and Laura, can I put three more spreadsheets under the Julie spreadsheet? Quinn111, You can have many worksheets, not just three in a workbook, but all these can only be on one level. You could have another workbook named Julie which you open (using code) from the Julie sheet in Linda. This will give the appearance of different levels of worksheet. Henry "quinn111" <quinn111@discussions.microsoft.com> wrote in message news:5923948A-D92D-4554-8592-49F06A0D7A11@microsoft.com.....

test
test ...

Can i turn a cell into a listbox and refer to the list value using the cell's reference
I would like to turn a cell ie (B2) into a listbox , the listbox will contains a range of cells ie (A2:A20) from another sheet in the same file. I would then like to be able to refer to B2 in VB or if statements i.e. =if(B2 = "Wheat", 0,1) I played around with "Create List" by right clicking a cell, but i didnt seem to do what i wanted. TIA Doug Hi Douglas maybe data / validation - list, with A2:A20 as the source which gives a drop down arrow in the cell would give you what you need? Cheers JulieD "Douglas" <dougsdir24@yahoo.com> wrote in message ...

Disappearing Fonts
I wonder if there's something strange going on with Microsoft Updates or something. My wife's XP machine and my Vista/64 system both are having font-loss problems concurrently... and we don't even share a network. Those fonts in the system's installed list shown beside an image of an 'O' are unaffected, but older 'TT' (TrueType) fonts are disappearing from the system font list. We happen to store all our fonts in another 'safety' folder, and I can point the font installation utility to a font in that folder and click Install. Then I get...