PDA

View Full Version : Change font of a Non-English TextBox



ahaider7
11-25-2012, 11:52 PM
Please consider the following piece of code
With ActivePresentation
Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
With sldNewSlide
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 50, 200)

With shpCurrShape
With .TextFrame.TextRange

'------------ Below is an ARABIC string
.Text = ChrW$(&H6A9) & ChrW$(&H64A) & ChrW$(&H641) & " " & ChrW$(&H62D) & ChrW$(&H627) & ChrW$(&H644) & ChrW$(&H643)

With .Font
.Name = "someFontName" '-------------- THIS LINE IS NOT WORKING
.Size = 65
End With

End With
End With

End With
End With
As indicated above, the font of arabic text is not being changed. Font change works well when the textbox contains english text. In case there is mixed arabic & english text, the english font is changed but arabic text stays in the default font (i.e Arial).

This code was working fine in Office 2003, but I came across this problem when trying to run in Office 2007/2010. I have double checked, the font I'm trying to specify is installed on the computer.

Although I have tested with arabic script languages only (arabic/urdu/persian etc), but I guess this problem will come up when dealing with any non-latin-script language.

Any suggestions? seems like a bug in later versions of ms office.

Paul_Hossler
11-26-2012, 02:47 PM
Seems to work ok for me (of course, I can't actually read it)



Option Explicit
Sub test()
Dim sldNewSlide As Slide
Dim shpCurrShape As Shape
With ActivePresentation
Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
With sldNewSlide
' original Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 50, 200) 'left, top width height
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 500, 50) 'left, top width height

With shpCurrShape
With .TextFrame.TextRange

'------------ Below is an ARABIC string
.Text = ChrW$(&H6A9) & ChrW$(&H64A) & ChrW$(&H641) & " " & ChrW$(&H62D) & ChrW$(&H627) & ChrW$(&H644) & ChrW$(&H643)

With .Font
.Name = "Arial Unicode MS" '-------------- seems to work with or with out a .Name
.Size = 65
End With

End With
End With

End With
End With
End Sub


Paul

John Wilson
11-27-2012, 03:51 AM
I see the same as Paul but I always get Arial whatever font I specify.

ahaider7
11-27-2012, 07:40 PM
Thanks both for the replies.

@Paul, No it is not working for you. Please place the cursor inside the textbox, and you will see the font still as default one (Arial). Had the font changed to "Arial Unicode MS", it would have looked like the attached image.

Paul_Hossler
11-28-2012, 11:54 AM
Sorry I mis-understood --

I believe that PP tries to do a font substatition if it needs / wants to, especially for the higher order unicode characters

In 2007, in the [Design] tab, [Themes], [Fonts] you can create a new theme and use that.

In the screen shot, the 'English' is in Bookman, but the Arabic is in Arial Unicode

Maybe that'll help??? The addition of 'Themes' with Office 2007 might be the reason there's a difference from your working 2003 version


Option Explicit
Sub test()
Dim sldNewSlide As Slide
Dim shpCurrShape As Shape
With ActivePresentation
Set sldNewSlide = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
With sldNewSlide

Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 25, 50, 500, 50) 'left, top width height

With shpCurrShape
With .TextFrame.TextRange

With .Font
.Name = "Bookman Old Style"
.Size = 65
End With

'------------ Below is an ARABIC string
.Text = "abc" & ChrW$(&H215B) & " -- " & _
ChrW$(&H6A9) & ChrW$(&H64A) & ChrW$(&H641) & " " & _
ChrW$(&H62D) & ChrW$(&H627) & ChrW$(&H644) & ChrW$(&H643)


End With
End With

End With
End With
End Sub


Paul

ahaider7
07-03-2013, 09:49 AM
Bumping up this thread because I found solution to my problem.

There are different Name properties in the Font class for different scripts. In my case, I had to use NameComplexScript property.

The portion of code that didn't work, should be like this
With .Font
.NameComplexScript = "Arial Unicode MS"
.Size = 65
End With
Here is a list of all Font members: http ://goo.gl/1qkM3 [sorry, can't post full links]

Paul_Hossler
07-03-2013, 03:48 PM
Thanks for posting the solution

Paul