[RESOLVED] Charsets, Fonts and Codepage questions
Hello everybody,
I have a question about charsets. I have an application in which on load I initialize the fonts the form and controls using whatever fonts are set in the users windows. Now I am porting this application to use arabic fonts. I am able to this by simply calling the charset property
Quote:
obj.Font.Charset = 178 'Arabic Charset
My question is this, what if the current font doesn't support arabic script? I can always set the font name
Quote:
obj.Font.Name = "Traditional Arabic" 'Some arabic font
but would like to use the font that is set in the users windows interface.
Here are my questions
1. Is there way of knowing if the current font can display arabic script or not? And if so use it, and if not then use a specfic arabic font?
2. What is the best way of determining if a system can display arabic fonts? Is it GetSystemMetrics(SM_MIDEASTENABLD) the only way or is there something else?
3. Should the codepage be set? Or by setting the charset that is enough?
4. I read this on the internet
Quote:
cmdMyButton.Font.Charset = charsetCyrillic
cmdMyButton.Font.Name = ""
cmdMyButton.Caption = "Чао а тутто ил мондо!"
Setting the font name to an empty strings causes the Font object to choose the default font for the control's code page. Of course, you can also explicitly set a font name that you know supports that code page.
Does this mean that I just use the above code and it will select the default font that works with that specfic charset?
Thanks for your assistance.
Re: Charsets, Fonts and Codepage questions
Different parts of the GUI use different fonts.
Code:
Control Panel -> Display -> Appearance -> Advanced
However, I only see SPI_GETICONTITLELOGFONT for the SPI API:
http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx
Quote:
Originally Posted by MSDN
SPI_GETICONTITLELOGFONT Retrieves the logical font information for the current icon-title font. The uiParam parameter specifies the size of a LOGFONT structure, and the pvParam parameter must point to the LOGFONT structure to fill in.
So, you need to use Theme based API, GetThemeFont.
http://msdn.microsoft.com/en-us/libr...45(VS.85).aspx
With Font based PropertyIdentifiers:
Code:
TMT_FONT
TMT_BODYFONT
TMT_CAPTIONFONT
TMT_GLYPHFONT
TMT_HEADING1FONT
TMT_HEADING2FONT
TMT_ICONTITLEFONT
TMT_MENUFONT
TMT_MSGBOXFONT
TMT_SMALLCAPTIONFONT
TMT_STATUSFONT
By using GetThemeFont to acquire the LOGFONT, you can check the charset member:
Member
Relevant Values
Code:
Middle East language edition of Windows:
ARABIC_CHARSET
HEBREW_CHARSET
Quote:
3. Should the codepage be set? Or by setting the charset that is enough?
Where?
Yes, Question 4 is true. From MSDN LOGFONT:
Quote:
.lfFaceName
A null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 TCHAR values, including the terminating NULL. The EnumFontFamiliesEx function can be used to enumerate the typeface names of all currently available fonts. If lfFaceName is an empty string, GDI uses the first font that matches the other specified attributes.
Hope this helps :D
Re: Charsets, Fonts and Codepage questions
Thank you for your answers.
I get the system font and then apply that font to all the controls and form. For example when I get my current font it is Tahoma.
If I assign the charset
obj.Font.Charset = 178
under the system font (which in my case happened to be Tahoma) it works correctly. However let us say the current system font wasn't compatible with the arabic script. Just assigning the charset will not work.
Basically in pseudo-code I would like to do the following:
Code:
IF SystemFontIsEnabledForArabicScript Then
obj.Font.Charset = 178
obj.Font.Name = "SystemFont"
ELSE
obj.Font.Charset = 178
obj.Font.Name = "" 'Which will take the first compatible font
END IF
I don't know how to determine if current system font is enabled for arabic script or not.
Also if I enter into the ELSE statement what if there isn't any fonts on the system compatible with the arabic script? Is my GetSystemMetrics(SM_MIDEASTENABLD) enough to tell me that I cannot display arabic?
Thanks again for your assistance.
Re: Charsets, Fonts and Codepage questions
Maybe EnumFontFamiliesEx Function?
Oops, already mentioned. Sorry!
Re: Charsets, Fonts and Codepage questions
Quote:
Originally Posted by Hassan Basri
I get the system font and then apply that font to all the controls and form.
How do you get the "System" font? What function(s) do you use? Or do you just create a new StdFont Object and let VB locate the default font? (in my case, MS Sans Serif. Never saw that one coming! lol), or do you reference a font of a control on application start? I hope you dont mean the bitmap font System.
Quote:
Originally Posted by Hassan Basri
However let us say the current system font wasn't compatible with the arabic script. Just assigning the charset will not work.
Create a StdFont object from scratch.
vb Code:
Dim f As StdFont
Set f = New StdFont ' MS Sans Serif (NOT Arabic Compatible)
f.Name = "FixedSys" ' FixedSys (NOT Arabic Compatible)
f.Charset = 178 ' Arial (Arabic Compatible)
f.Charset = 0 ' Arial (Arabic Compatible)
f.Name = "Tahoma" ' Tahoma (Arabic Compatible)
f.Charset = 178 ' Tahoma (Arabic Compatible)
f.Name = "" ' Arial (Arabic Compatible)
Quote:
Originally Posted by Hassan Basri
I don't know how to determine if current system font is enabled for arabic script or not.
Find the "System" font and check the Charset member.
vb Code:
Private Declare Function EnumFontFamiliesEx Lib "gdi32.dll" Alias "EnumFontFamiliesExA" (ByVal hdc As Long, ByRef lpLogFont As LOGFONT, ByVal lpEnumFontProc As Long, ByVal lParam As Long, ByVal dw As Long) As Long
When calling, remember that the LOGFONT struct you're passing can make the function "specialized"
Quote:
lfCharset
If set to DEFAULT_CHARSET (0), the function enumerates all fonts in all character sets. If set to a valid character set value (Like Arabic, 178), the function enumerates only fonts in the specified character set.
Quote:
Originally Posted by Hassan Basri
Is GetSystemMetrics(SM_MIDEASTENABLD) enough to tell me that I cannot display arabic?
I guess. Check the locale.
vb Code:
Const LOCALE_USER_DEFAULT = &H400
Const LOCALE_SENGCOUNTRY = &H1002 ' English name of country
Const LOCALE_SENGLANGUAGE = &H1001 ' English name of language
Const LOCALE_SNATIVELANGNAME = &H4 ' native name of language
Const LOCALE_SNATIVECTRYNAME = &H8 ' native name of country
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
MsgBox "You live in " & GetInfo(LOCALE_SENGCOUNTRY) & " (" & GetInfo(LOCALE_SNATIVECTRYNAME) & ")," & vbCrLf & "and you speak " & GetInfo(LOCALE_SENGLANGUAGE) & " (" & GetInfo(LOCALE_SNATIVELANGNAME) & ").", vbInformation
End Sub
Public Function GetInfo(ByVal lInfo As Long) As String
Dim Buffer As String, Ret As String
Buffer = String$(256, 0)
Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer))
If Ret > 0 Then
GetInfo = Left$(Buffer, Ret - 1)
Else
GetInfo = ""
End If
End Function
Quote:
Originally Posted by Hassan Basri
Thanks again for your assistance.
No problem :)
Re: Charsets, Fonts and Codepage questions
Thanks again for your assistance,
I have a class that gets the system font. If you are interested I can post it.
In any case, I found a very simple solution to the problem. Basically, I get the system font. Then I set the charset, THEN I set the font name. If the charset remains what I set, I know that that font is compatible. Otherwise I use the first default font that is compatible. Here is the code:
Code:
'I already got my default font and set it for the form
'Here I store the values
intCharset = frm.Font.Charset
strFontName = frm.Font.Name
'Here I set the charset and font
frm.Font.Charset = m_intFontCharset
frm.Font.Name = strFontName
'Now I check did the charset change or remain the same?
If frm.Font.Charset <> m_intFontCharset Then
'Charset doesn't work with current font so I use the default font by
'sending an empty string
frm.Font.Charset = m_intFontCharset
frm.Font.Name = ""
Else
'Current font is compatible with the charset
End If
Re: Charsets, Fonts and Codepage questions
Quote:
Originally Posted by
Hassan Basri
Thanks again for your assistance,
I have a class that gets the system font. If you are interested I can post it.
In any case, I found a very simple solution to the problem. Basically, I get the system font. Then I set the charset, THEN I set the font name. If the charset remains what I set, I know that that font is compatible. Otherwise I use the first default font that is compatible. Here is the code:
Code:
'I already got my default font and set it for the form
'Here I store the values
intCharset = frm.Font.Charset
strFontName = frm.Font.Name
'Here I set the charset and font
frm.Font.Charset = m_intFontCharset
frm.Font.Name = strFontName
'Now I check did the charset change or remain the same?
If frm.Font.Charset <> m_intFontCharset Then
'Charset doesn't work with current font so I use the default font by
'sending an empty string
frm.Font.Charset = m_intFontCharset
frm.Font.Name = ""
Else
'Current font is compatible with the charset
End If
I was implying that here, but not in so many words:
vb Code:
Dim f As StdFont
Set f = New StdFont ' MS Sans Serif (NOT Arabic Compatible)
f.Name = "FixedSys" ' FixedSys (NOT Arabic Compatible)
f.Charset = 178 ' Arial (Arabic Compatible)
f.Charset = 0 ' Arial (Arabic Compatible)
f.Name = "Tahoma" ' Tahoma (Arabic Compatible)
f.Charset = 178 ' Tahoma (Arabic Compatible)
f.Name = "" ' Arial (Arabic Compatible)
Glad to be of help! :thumb::thumb::thumb::thumb::thumb::thumb::thumb: