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

Similar Articles

[PageSpeed] 49

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:

how can I embed fonts in Excel?
looking for any updated information on embedding a font into an excel worksheet. Mel Cannot be done. Gord Dibben Excel MVP On Mon, 16 May 2005 14:59:19 -0700, Mel <Mel@discussions.microsoft.com> wrote: >looking for any updated information on embedding a font into an excel >worksheet. ...

Font color for negative numbers #2
I need help in changing the font color for negative numbers to red in a spread sheet I have tried searching and then find using -$ find and it doesnt seem to work Try #,###.00_);[Red](#,###.00);0.00 The colors are [BLACK], [BLUE], [CYAN], [GREEN], [MAGENTA], [RED], [WHITE], [YELLOW], [COLOR n] with n from 1 to 56 Also look here (found with Google search: Excel custom format http://www.bettersolutions.com/excel/EVD243/QM215412021.htm best wishes -- Bernard V Liengme Microsoft Excel MVP www.stfx.ca/people/bliengme remove caps from email "Regards" <Regards@discussions.microsoft...

(Outlook 2003) How can I AUTOARCHIVE only selected folders?
I would like to Autoarchive selected folders, for which I set autoarchive via the (select folder) right click-select PROPERTIES menu item. But every time I set up a folder autoarchive, OL insists on setting Autoarchive properties for the entire PST file, and then as a result, all folders would be autoarchived, which I don't want. I'm confused about how this should work. Thanks for clearing this up for me. ILOO ...

simple can't find form question
I have a form with some simple code behind it which reads like this: with Forms![frmNextFixtureTypeOption] .[lblNextAlpha].Caption = strNextAlpha .[lblNextNumeric].Caption = strNextNumeric end with stDocName = "frmNextFixtureTypeOption" DoCmd.OpenForm stDocName, , , stLinkCriteria the second part (where I open the form) works fine, but the first (where I set the caption for 2 of the controls) does not - it returns an error "can't find form"... as always, many thanks in advance, mark O...

Can Toolbars Be Locked?
Hi there, I use Outlook 2003 (part of Office Pro) and have several toolbars that I like to access. Currently they tend to line up one beneath the other, therefore taking up a lot of screen space. Is it possible to lock the toolbars so that when you exit out of Outlook and then go back into Outlook again they are in the same position as when you left? Otherwise I suppose my only other option is to go in and edit the icons that appear on the Standard or Advanced toolbars. On XP SP2 with all XP and Office updates applied.. Thanks so much. Lynn Lynn Q <manxcat@sympatico.ca> ...

2004 Mac Microsoft Excel: Lost corner! Can NOT shrink the window!! #3
I am new to Mac, so if anyone can tell me how to fix this problem I have, it will be appreciated. When I launch Excel, open an existing file by choosing 'open' under 'File' at toolbar, Excel opens up a window to show all the files, folders etc. from my computer HD and extermal HD etc. in one window with the tile 'Open: Microsoft Excel'. Somehow, this winow in my Excel program has corner push down out of screen. Therefore, I can not grab the corner to shrink the window to fit my computer screen. I barely see 'Cancel' and 'Open' icons at the bottom of the...

Can't get rid of rogue PST file in Folder List
Hi, I have Outlook XP SP1 and latest updates. After a recent reinstall of WinXP I now have 2 PST files listed. One is my normal one, and the other is pointing at a file that doesn't exist. I get the error when I click on it: "Unable to display the folder. Microsoft Outlook could not access the specified folder location. The path specified for the file ... is not valid." I can't right-click to delete it. If I try to create a PST where it is hoping to find one, it won't open it anyway. I've removed all references (there were 2) to that PST from registry. What els...

Can't print landscape from network printer HP 4050N
Dear all, I can't print landscape from the network printer although i've re-install MS OFFICE 2000, uninstall and update HP drivers and check the settings(from portrait to landscape) from the printer also can't solve this problem. Not only me having this problem, there are several user also faced this problem too. Therefore, I suspect it's not the Windows 2000 issue. Any advise will be much appreciated. Thank you. Not an expert but, are the drivers installed on the individual machines? (they should be). -- Regards; Rob -------------------------------------------------------...

Can I create a Survey on MS CRM?
I am on the process of evaluating MS CRM. So far I have been happy with what I have seen but I wonder if there is any way to create surveys on it. Sometimes the sales department calls customers in order to fill, for example, a satisfaction survey. I don=92t expect the customers been able to fill the survey because that will require additional CRM licenses but I do expect sales department been able to call the customer and fill the survey with the information that was gather. Of course I also expect to be able to generate a report with the survey summary. you can do by using Marketing list an...

How can i change tab control 's background color
I create a class derived from CTabCtrl. If i handle the WM_PAINT message, there're nothing left on the control. Does it mean that I should draw all the things? And the WM_CTLCOLOR doesn't work,too. How can I change the background color simply? ...

can't view background in publisher, only in print preview
please help, the background has vanished from publisher pages, it shows up in print preview and prints ok but it's difficult to work with without seeing a background. clyde wrote: > please help, the background has vanished from publisher pages, it > shows up in print preview and prints ok but it's difficult to work > with without seeing a background. ============================== Which version of Publisher? Just a thought...but is the background on the Master Page? If it is...try going to... View and uncheck...Ignore Master Page. -- John Inzer MS-MVP Digital Med...

I can not receive e-mail.
When I send/receive I keep getting an error message, Task 'mail.lig.bellsouth.net - Receiving' reported error (0x8004210A): 'The operation timed out waiting for a response from the receiving (POP) server. If you continue to receive theis message, contact your server administrator or Internet service provider (ISP) I am not sure how to proceed. Disable your antivirus scanner for outgoing mail and check your server settings with Bell South. http://support.microsoft.com/default.aspx?scid=kb;en-us;813518&Product=ol2002 "sidvr" wrote: > When I send/receive I ke...

Can't insert a picture
When i try to insert a picture, Outlook 2007 faults with apologies. This occurs while the browse window is partly filled out. this has been the case since I upgraded from a previous version. I have tried all the suggestions which were in the "Sepron" post, 11/22/07. Help? --Terry What exactly is logged to the Event Viewer about this? See http://www.msoutlook.info/question/317 -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.inf...

Can Visio also UML?
Hi, Can anyone tell me, - if Visio can UML, can it create UML Diagram for Software design (and generate code)? - Can Visio create Database Design and intergration with Database? Thanks TNL The Enterprise Architect edition of Visio (comes when you order vs.net enterprise architect) is the product that works in that area. For a description you might check the v2002 EA documentation, since it hasn't changed much. Al "TNL" <le.nhan@web.de> wrote in message news:evXOxeaAEHA.3804@TK2MSFTNGP09.phx.gbl... > Hi, > > Can anyone tell me, > - if Visio can UML, can it c...

Can't move worksheet after saving (mac)
I hope this is not a dumb question, but often after saving a worksheet the title bar ( and maybe first couple of rows) moves out of sight at the top of my screen. As far as I can see, it is then impossible to move the worksheet to access the first two rows, as this is only possible by dragging on the title-bar. So I have to close and reopen the worksheet, after which the title bar and top of the sheeet is visible., but this is very annoying of course. Could this be a bug or am I missing something? -- funkster99 ------------------------------------------------------------------------ f...

Can Microsoft Exchange be installed to get just POP mail?
We are a small company of 5 staff with Broadband and POP mail from our service provider. Can Microsoft Exchange be used to get our POP mail? Thanks Yes. Use SBS - much more affordable for small orgs. -- Bharat Suneja MCSE, MCT www.zenprise.com blog: www.suneja.com/blog ----------------------------------------- "Rillo" <james@taiwo.net> wrote in message news:1142439289.365543.169670@j52g2000cwj.googlegroups.com... > We are a small company of 5 staff with Broadband and POP mail from our > service provider. Can Microsoft Exchange be used to get our POP mail? > Thank...

Anyone know if exchange allows/can allow plus addressing
Anyone know if exchange will accept and handle plus addressing correctly? Here's what I am talking about: http://en.wikipedia.org/wiki/E-mail_address#Plus_.28or_Minus.29_addressing So if my email is: someone@mycompany.com I should also receive emails sent to: someone+tag@mycompany.com I am not an exchange admin at my company, but currently it doesn't work at my company. Just wondering how to present the idea to the admins if possible. Thanks You can have both '+' and '-' signs in local part of e-mail address - Exchange will deliver message just fine. But tho...

Password protection in macro ( Anybody can view my password in VB
Hi, I have inserted macro to protect all of my sheets, and password for the protection. but anybody can view code of my macro and take my password. what is the solution for this insecurity. -- Life isa journey not a destination Sherees, Additional to Micky's answer you should be aware that while the suggested method will deter the honest anyone with Google and the desire to do so could open your VB project quite easilly. VB project protection is better than worksheet protection but is easilly defeated. -- Mike When competing hypotheses are otherwise equal, adop...

how can I create a custom design for business card
I saved a picture on my desktop that I would like to use for my business card design.How do I go about doing it if it's possible? Thank you in advance Jason Jason Use the 'insert' picture from file, and then use the 'format' picture for placement, layout et al.. -- Mike Hall MVP - Windows Shell/User http://dts-l.org/goodpost.htm "wrenchnjai1" <wrenchnjai1@discussions.microsoft.com> wrote in message news:2FF8A318-3324-445C-A07F-65B47F3C3258@microsoft.com... >I saved a picture on my desktop that I would like to use for my ...

my picture attachments are opening in word and I can't view them
I can't open attachments because outlook is opening them in word Outlook just obeys the settings Windows uses. If you save the attachment to your hard drive then double-click on it, what happens? "md1914" <md1914@discussions.microsoft.com> wrote in message news:61AF0911-41EE-4C18-A808-A0235A3E249D@microsoft.com... >I can't open attachments because outlook is opening them in word ...

can't open an Excel 97 file
Hi all, We have a 2 MB Excel 97 file that suddenly sent an error message when trying to open it: "imposible leer archivo" (that is "impossible to open file") We do not have a backup copy of the file, do you any way to recover the information saved on that file? Thanks, Betty This has been multiposted. "Betty" <no@quiero.spam> wrote in message news:%23fwNqxksFHA.464@TK2MSFTNGP15.phx.gbl... > Hi all, > We have a 2 MB Excel 97 file that > suddenly sent an error message when > trying to open it: > "imposible leer archivo" (th...

Can not access CRM 4.0 from a client machine after initial setup
Hi, I just finished installing CRM 4.0 and the client side. When I go through the wizard to connect the server, it is not accepting the intranet address, "The specified MS CRM server is not available. can not access through the browser either. I can access it while logged onto the server. I did create the domain user onto the CRM and gave all roles. The address is: "http://crm:5555/CPA-CRM/loader.aspx". I am running SBS 2008, and a separate server for CRM/SQL2005. Another question: How can I change it where it is only "http://crm/loader.aspx" thanks, Joe ...

How can I get a combo box to get data based on a text box?
Hi, I have a text box that looks up an ID number from a table. I want the User to type in an ID and then have a combo box on the same form that gives a list of dates that correspond to that ID in the text box. Right now, the combo box displays all the dates from all the ID's. I want it to only show the dates that are linked to that ID. Please help, Thanks Use the text box's AfterUpdate event to modify the combo box's RowSource property: Me.ComboBox1.RowSource = "SELECT ... FROM ... WHERE FieldID=" & Me.TextID & ";" tyler.deutsch@gmail.com wrote...

Access runtime. Can I use this?
Hi I have developed a database that is split in to front and back end, and has user level security using a Workgroup Information file. Is it possible to convert these to runtime based programs? Stapes Stapes wrote: > Hi > > I have developed a database that is split in to front and back end, > and has user level security using a Workgroup Information file. > > Is it possible to convert these to runtime based programs? > > Stapes The runtime is a crippled version of Access used to run (normal) Access files on PCs where the retail version of Access is not installed. ...

How can I send a multi page document by email from publisher 2003
Publisher 2003 allows me to send one page of a publication as an email. how can I send multiple pages in one email? Attaching to an email is no good as most recipients do not have a program to open the attachment. I need help urgently thanks in advance for your prompt reply Spider25160 <Spider25160@discussions.microsoft.com> was very recently heard to utter: > Publisher 2003 allows me to send one page of a publication as an > email. how can I send multiple pages in one email? Attaching to an > email is no good as most recipients do not have a program to open the > attachme...