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
1492 Views

Similar Articles

[PageSpeed] 40

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:

Only one user at a time can access OWA
Using Exchange 5.5 SP3 on W2K. Only one user can log on using OWA at any one time. As soon as the first user logs out the next can then log on, but in a organisation of 1300 - bit of a problem. Previously we did have things working fine with Exchange 5.5 on WinNT but a hacking attack put paid to that system! Have run through MS trouble shooting but found no mention of this problem anywhere else. Any suggestions welcomed Regards Mike Cameron cameronm@queensbury.beds.sch.uk (Mike Cameron) wrote: >Using Exchange 5.5 SP3 on W2K. Only one user can log on using OWA at >any one time. As...

How can we use Excel to calculate interest with daily compounding
Would like to create worksheet with daily compounding but without having to set a row per day. Any suggestions? If you have an annual interest rate - say 5%, you calculate daily compounded interest by: =((1+5%/365)^(#days)-1)*principal amount If your principal amount is $1,000 and the # of days is 60, then the interest is $8.25 vs $8.22 simple interest "Myra" wrote: > Would like to create worksheet with daily compounding but without having to > set a row per day. Any suggestions? ...

ANOVA procedures and t-test equal variance
In looking through Excel I see that it has both the ANOVA procedure and a t-test with equal variances and a t-test for unequal variances. One of the assumptions that is made in both the "standard t test" and ANOVA is that the variances are equal. Yet, Excel seems to have no test for homoscedasicity (oh what a cool word). How do you know these procedures are ok to use if you have not checked the assumption of equal variances? Noosa - > In looking through Excel I see that it has both the ANOVA procedure and a > t-test with equal variances and a t-test for unequal vari...

test of wizard
-- This posting is provided "AS IS" with no warranties, and confers no rights. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=f61980a5-9a9d-4399-8044-95f7dc1810...

Publisher: business name or word in all font styles
I like to create logos and do business graphic design. I would really like to have a tool in Publisher where I could type in the name of the company and have Publisher creat a list in a pop-up or page with it in every font style that is available. If this is already available, sorry - but please let me know how to do it. Publisher 2003 ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this li...

Can't email mail enabled folder on second server
1 2003 domain 2 2003 exchange servers (native mode) I just recently installed a second exchange server. When I create a public folder on the second server and mail enable it with an SMTP address, I am not able to email the folder from an external address. The message queue's up on the 1st server in the local delivery queue. I am however able to email it internaly. Also clients who mailboxes are on the old server do not see the public folders on the new server and vise versa. Any suggestions? Thanks in advance TKE402 Does the new folder show up in the public folder hierarchy in th...

help I can not post
sorry another test ...

class wizard, where does class window "discover" what messages window can handle?
Where (what file) does window use or how does Class Wizard discover, what messages a window can handle and receive? For usere defined messages, I remember there being a way to add the to some file, so that they are visible in ClassWizard in message list. Martin Ortiz wrote: > Where (what file) does window use or how does Class Wizard discover, what > messages a window can handle and receive? > For usere defined messages, I remember there being a way to add the to some > file, so that they are visible in ClassWizard in message list. > > I don't think there is a way t...

Can read only in message list
I got two e-mails today that I can only read in the message list. When I open the message there is no message there, but I can read half of the message in the short preview list. ...

Change the font size of the Column/Row headers?
Hi Is this possible, & if so, could you point out where? I can't find it. Thanks Dave F. Dave Format>Style>Normal>Modify>Font. Set higher or lower and OK your way out. Note: this will initially change all the cells' font to that setting, but you can change those as you wish. The column and row headers will stay at the new setting. This will not affect previously saved workbooks, just the one you're in. To have this as default, save a workbook with these settings as a Template(*.xlt) Name your workbook "BOOK"(no quotes). Excel will add the .XL...

Hit testing
I'm trying to implement client area hit testing in a MDI application. In my document, I have a list of graphic objects (e.g. polygons) that are displayed in the view. The list can get pretty long, so the hit test algorithm needs to be fairly efficient. My first attempt at this was to add HitTest(CPoint) function to the graphic object class. In this function I created a Region and then tested it. Something like... int CPolygon::HitTest(CPoint Point) { CRgn Rgn; Rgn.CreatePolygonRgn(PointList.GetData(), PointList.GetSize(), WINDING); if (Rgn.PtInRegion(Point)) ...

I can't export distribution lists in Outlook 2003
I am trying to export distribution lists in Outlook 2003 to load onto another comupter that is on another domain. I am doing this by using the import/export wizard on the original PC, exporting the contact list with the distribution lists into a PST, then importing the PST into the destination PC. The problem that I am having is that when I import the .pst into the destination PC on the other domain, just the name of the list is there. The members of the list are not there. Can anyone help...i've been looking for a solution for days! Thanks to anyone that can help!! As we have docum...

How can I protect cells only?
Hi, At work we have shared excel file and want to protect some cells (not the whole sheet) which contains formulas?upon clicking the cell, I want it to appear warning message. Regards, SRM actually all cells are protected by default. what you need to do is unprotect the cells you want everyone to have access to, then protect the sheet. SRM wrote: >Hi, >At work we have shared excel file and want to protect some cells (not the >whole sheet) which contains formulas?upon clicking the cell, I want it to >appear warning message. > >Regards, >SRM -- Mark Brindamour m...

Can't open word file with password: "can't find encryption code"
I have a word file with a password and encrypted used to open in word 2003 with the compatibility pack as the file was created in another pc in word 2007. Now, after installing office 2007, can't open that file: it says can't find the encryption code or source. Thank you. ...

How can I open .pub 1995 files?
I have old .pub files -1995 but have 1998 and 2000 software and am trying to find a way to open the files. I don't use Norton and am a mobile worker so am go crazy about not being able to access my work. Publisher 98 and 2000 will open 95 publications. Are you sure they are 95 files? You can send me one of the files and I will try to open it for you. mary-sauer at columbus.rr.com -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "jvb1962" <jvb1962@discussions.microsoft.com> wrote in message news:6B50B451-F93D...

Can't size window
What would override the ability to size my SDI's window? This is what I have: cs.style = WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; When I restore down and click, the cursor changes to size the border, but there is otherwise no effect. I am thinking that I may have done something a few years back to prevent sizing, but I do not see what that would be. http://msdn2.microsoft.com/en-us/library/h464d4f3.aspx Also, look under: Window Size and Position http://msdn2.microsoft.com/en-us/library/b5wzwdk7.aspx#_mfc_window_size_and_pos...

ignore -- testing
Haven't seen a posting in several NGs since 6/25. Just curious if GG is updating these NGs. I'm using the "old" user interface. Can't find these NGs using the new GG "experience". just testing "joeu2004" <joeu2004@hotmail.com> wrote in message news:812e733c-2d95-4174-8a3d-d08ecc672145@e17g2000prj.googlegroups.com... Haven't seen a posting in several NGs since 6/25. Just curious if GG is updating these NGs. I'm using the "old" user interface. Can't find these NGs using the new GG "experience". testing a...

Can't add to the dictionary
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: imap I am having the same problem reported by Dunc. And, I went through the recommended &quot;make a change and then resave&quot; steps. <br><br>Still no improvement. <br><br>I sure wish there were a REAL fix to this problem. It's pretty frustrating. Karl_Schubert@officeformac.com wrote: > I am having the same problem reported by Dunc. And, I went through > the recommended "make a change and then resave" steps. > > Still no impro...

How can I hide check box created via FORMS together with column?
Hey guys, how can I hide a check box created using FORMS together with column it is placed in (or in some other way). "Move and size with cell" option is not active in object positioning for check boxes created via FORMS as opposed to those created via CONTROL TOOLBOX. Thanks, Max I think you'll have better luck (pronounced easier time!) with the checkboxes from the Control toolbox toolbar. But maybe you could have a macro that hides the columns/rows and also looks at the objects to see if they should be .visible = false. And the same kind of macro to make the checkbox&#...

How can I add tabs to Bluetooth devices with windows default drive
I want to add an extension profile like FTP to windows default bluetooth driver stack and show a tab when right click on the bluetooth icon. It is said that "By impltmenting a shell proterty handler for the application" in Bluetooth Wireless Technology FAQ. I've tried that but it is only add a property sheet in Bluetooth settings, and my question is how to add a tab in the context menu just like "send a file" tab. Does it need a ContexMenuHandler and where should I registe it? ...

Moving Gmail Acct to Outlook? Passes Test but won't work Why/Fix?
I have followed the directions on the gmail page on moving my acct to outlook. It passes the test and yet does not work. What gives? How do I fix? Is this some weirdness between google and microsoft. Any suggestions? Help! Could you be a little more specific? What doesn't work? Does it send? Doesn't receive? Do you get any error messages? What version of Outlook? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP Roland Schorr & Tower http://www.rolandschorr.com Microsoft OneNote FAQ: http://www.factplace.com/onenotefaq.htm **I apologize but I am unable to respond to direct r...

Testing an Exchange backup
Hello everyone I have been backing up my Exchange database (SBS 2003) using an online backup with the NTBackup utility, and everything appears to be working fine: backup files created in the right place at the right time, and a log file saying that the backup was successful. However, I would like to make sure that the backup has worked by using it to restore data. My problem is I want to be absolutely sure that if everything goes wrong and I can't restore, that I won't lose any data. I wonder whether the following plan would work? 1. Dismount my databases. 2. Rename my priv1.e...

How can run an Excel macro program using DOS command?
I want to run an Excel macro program using batch job but I don't know what the DOS command is? Put the code in the Workbook_Open procedure of some workbook and use the DOS command to open the workbook. However, do be aware that depending on your security settings, XL may not enable the code at all or it might display a "this file contains macros" warning dialog box that will require human intervention. -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article <155ca01c41ae9$b4b37b20...

Tests?
Why do so many individuals need to jump on someone who posts a test? A higher percentage than Ivory soap put a clear indicator in the Subject line it's a test message. Seems the least educated of us all could identify this to make the decision to go right on by, it's a test. But what happens is a deluge of messages are sent to criticize the individual who is trying to solve a problem. And many of the criticisms are "not on topic" (like the ng they're in has "and criticism" as part of the ng title. But what is allowed is the use of vomit vocabulary! Certainly...

Can Excel Choose from a List What Makes a Particular Total?
Suppose a customer has 60 unpaid invoices. The customer sends me a check paying a certain number of the invoices but doesn't indicate how many invoices or which ones. Let's assume I cannot contact the customer for more information. Is there a way to put all 60 amounts in Excel along with the amount of the check and have Excel try all possible combinations of those invoices to determine which combination, if any, matches the amount of the check? Sounds like you need a better relationship with your customer.. -- Don Guillett SalesAid Software donaldb@281.com "Homeboy" ...