PDA

View Full Version : Determine language supported by font



MacroShadow
03-26-2012, 03:31 AM
Hello all experts,


Recently I've come across several macros to print samples of all fonts installed on the local machine, they loop thru all installed fonts and type a sample text for each one, the problem is that if the font doesn't support English (the language of the sample text) boxes show-up instead of the letters, is there a way to detect what language (or characters) is supported by each font?
Can this be done using VBA, or can someone provide another solution that can be used by VBA?

If it is possible, then for a font that doesn't support the language of the sample text, I can have it type text in a language that it supports.


Here is one of the macros:



Sub FontSamples() ' Samples all fonts installed ' Macro written 31 March 2006 by John McGhie Const SampleText As String = "the quick brown fox jumps over the lazy dog." & _ " THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0 1 2 3 4 5 6 7 8 9" Dim i As Long ' Make our own array because FontNames is FUBARed Dim AllFonts() As String Dim StyDoc As Document Set StyDoc = Application.Documents.Add ' Resize the array the way we want it (in case the user has an Option Base set) ReDim AllFonts( 1 To FontNames.Count) ' Load the array one by one from FontNames For i = 1 To FontNames.Count AllFonts(i) = FontNames(i) Next i ' Use the WordBasic sort because VBA doesn't have one!! WordBasic.SortArray AllFonts$() ' Adjust the styles we want to use in the document we just created With StyDoc.Styles With .Item(wdStyleHeading1) .Font.Color = wdColorBlue .ParagraphFormat.PageBreakBefore = False End With With .Item(wdStyleBodyText) .Font.Size = 36 .Font.Color = wdColorAutomatic End With End With ' Add a TOC so we can list the styles and find them later With StyDoc.TablesOfContents .Add Range:=Selection.Range, RightAlignPageNumbers:= _ True , UseHeadingStyles:= True , UpperHeadingLevel:= 1 , _ LowerHeadingLevel:= 1 , IncludePageNumbers:= True , AddedStyles:= "" .Item( 1 ).TabLeader = wdTabLeaderDots .Format = wdIndexIndent End With ' there's a bug in FontNames collection, in WD2003 we can't ' use For Each ... Next, it errors due to a type mismatch For i = 1 To UBound (AllFonts) With Selection .Style = wdStyleHeading1 .TypeText Text:=AllFonts(i) .TypeParagraph .Style = wdStyleBodyText .Font.Name = AllFonts(i) .TypeText Text:=SampleText .TypeParagraph .TypeParagraph End With Next i StyDoc.TablesOfContents( 1 ).Update Selection.HomeKey Unit:=wdStory, Extend:=wdMove End Sub




I posted this question at http-social.msdn.microsoft.com/Forums/en-US/worddev/thread/3f8c21b1-a0aa-4ea2-8674-c5debde0f018 where Bruce Song [MSFT] kindly provided me with c# code that would help me, unfortunately I have no experience in c#, and I've received no response to my inquiry.

Talis
03-26-2012, 10:56 AM
Here's the code set out properly but with no other changes:
Sub FontSamples()
' Samples all fonts installed
' Macro written 31 March 2006 by John McGhie
Const SampleText As String = "the quick brown fox jumps over the lazy dog." & _
" THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0 1 2 3 4 5 6 7 8 9"
Dim i As Long
' Make our own array because FontNames is FUBARed
Dim AllFonts() As String
Dim StyDoc As Document
Set StyDoc = Application.Documents.Add
' Resize the array the way we want it (in case the user has an Option Base set)
ReDim AllFonts(1 To FontNames.Count)
' Load the array one by one from FontNames
For i = 1 To FontNames.Count
AllFonts(i) = FontNames(i)
Next i
' Use the WordBasic sort because VBA doesn't have one!!
WordBasic.SortArray AllFonts$()
' Adjust the styles we want to use in the document we just created
With StyDoc.Styles
With .Item(wdStyleHeading1)
.Font.Color = wdColorBlue
.ParagraphFormat.PageBreakBefore = False
End With
With .Item(wdStyleBodyText)
.Font.Size = 36
.Font.Color = wdColorAutomatic
End With
End With
' Add a TOC so we can list the styles and find them later
With StyDoc.TablesOfContents
.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=1, IncludePageNumbers:=True, AddedStyles:=""
.Item(1).TabLeader = wdTabLeaderDots
.Format = wdIndexIndent
End With
' there's a bug in FontNames collection, in WD2003 we can't
' use For Each ... Next, it errors due to a type mismatch
For i = 1 To UBound(AllFonts)
With Selection
.Style = wdStyleHeading1
.TypeText Text:=AllFonts(i)
.TypeParagraph
.Style = wdStyleBodyText
.Font.Name = AllFonts(i)
.TypeText Text:=SampleText
.TypeParagraph
.TypeParagraph
End With
Next i
StyDoc.TablesOfContents(1).Update
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
End Sub

macropod
03-26-2012, 11:04 PM
As with your other post, this looks like nothing more than a cross-post of:http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/3f8c21b1-a0aa-4ea2-8674-c5debde0f018/#a9dc8f46-0e14-482d-9816-1752ecb9fd9d
with absolutely no recognition of the help you've been given - including a fully workable solution that you've succesfully installed!

fumei
03-26-2012, 11:44 PM
Fully workable? Really Paul? I must be missing something as well.

MacroShadow
03-27-2012, 12:11 AM
I posted this question at http-social.msdn.microsoft.com/Forums/en-US/worddev/thread/3f8c21b1-a0aa-4ea2-8674-c5debde0f018 where Bruce Song [MSFT] kindly provided me with c# code that would help me, unfortunately I have no experience in c#, and I've received no response to my inquiry.

Macropad as you can see I did mention it.
Please don't be so harsh with me, I'm a beginner.

macropod
03-27-2012, 12:24 AM
Fully workable? Really Paul? I must be missing something as well.
Moishy's last post in that thread seems to me to confirm that the solution did work and he was only needing advice on how to register the dll for use on another machine.

fumei
03-27-2012, 12:35 AM
I see no dll. I downloaded the file VS2010_Excel2010_CS_C_FontLibForVBA.

I see no dll.
Anyway, no matter. I do not really want to work with this anyway.

MacroShadow
03-27-2012, 01:40 AM
Macropad:

To me it seems that "What is the meaning of the numbers that are displayed in the immediate window, or in other words how can I convert between them and the actual characters and vice verse" as posted at http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/3f8c21b1-a0aa-4ea2-8674-c5debde0f018/#a9dc8f46-0e14-482d-9816-1752ecb9fd9dmeans that the solution was not understood, and so no use could be made of it!

fumei:

The file you downloaded is a vs project, you have to publish it to make the dll.