Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/ATS/ATSUI Text Rendering Japanese and Cirillic
Function:
Required plugins for this example: MBS MacCF Plugin, MBS MacCG Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/ATS/ATSUI Text Rendering Japanese and Cirillic
This example is the version from Tue, 3rd Aug 2015.
Project "ATSUI Text Rendering Japanese and Cirillic.rbp"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim pf as CPMPageFormatMBS Dim cpmpr As CPMPrinterMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS Dim ra as CPMRectMBS Dim res as CPMResolutionMBS dim g as CGContextMBS Dim cr as CGRectMBS Dim Text As String Dim Scale_Factor as double Dim ugol90 as single dim t as ATSUTextLayoutMBS dim s as ATSUStyleMBS const kATSUFromTextBeginning=-1 const kATSUToTextEnd=-1 Const Pi=3.14159265358979323846264338327950 Text="This is a text. Latin, Japanese or Cirillic ムミビプ (русский)" //(русский) - this is a russian text // ATSUI needs UTF16 strings! text=ConvertEncoding(text,Encodings.UTF16) ugol90=Pi/2 // Pi is 180°, so rotate a quarter is half pi ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS res = New CPMResolutionMBS ps.defaultPageformat pf ps.defaultPrintSettings pt cpmpr = ps.CurrentPrinter 'res = cpmpr.PrinterResolution("maxs") // maximum resolution 'pf.Resolution = res // make font bigger on maximum resolution Scale_Factor=res.Vertical/72 if ps.PageSetupDialog(pf) then if ps.PrintDialog(pt,pf) then ra=pf.adjustedpageSize ps.BeginDocument(pt,pf) ps.BeginPage(pf,nil) g=ps.PageContext if g<>Nil then g.SetRGBFillColor 0.0,0.0,0.0,1.0 g.TranslateCTM(1000, 1000) g.rotateCTM ugol90 // rotate 90° s=new ATSUStyleMBS s.Create s.Size=12.0*Scale_Factor t=new ATSUTextLayoutMBS t.Create t.SetTextPointerLocation text,kATSUFromTextBeginning,kATSUToTextEnd,len(text) t.SetRunStyle s,kATSUFromTextBeginning, kATSUToTextEnd t.SetCGContext g.Handle t.TransientFontMatching=true t.DrawText kATSUFromTextBeginning, kATSUToTextEnd,0,0 end if else MsgBox "g is nil!?" end if ps.EndPage ps.EndDocument end if end if End EventHandler
End Control
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim cg as CGContextMBS Dim cr as CGRectMBS Dim Text As String dim t as ATSUTextLayoutMBS dim s as ATSUStyleMBS // this is all only to draw const kATSUFromTextBeginning=-1 const kATSUToTextEnd=-1 Text="This is a text. Latin, Japanese or Cirillic ムミビプ (русский)" //(русский) - this is a russian text text=ConvertEncoding(text,Encodings.UTF16) Title=text cg=me.CGContextMBS if cg<>Nil then cg.SetRGBFillColor 0.0,0.0,0.0,1.0 // Create a font style with 12 Point font s=new ATSUStyleMBS s.Create s.Size=12.0 t=new ATSUTextLayoutMBS t.Create t.SetTextPointerLocation text,kATSUFromTextBeginning,kATSUToTextEnd,len(text) t.SetRunStyle s,kATSUFromTextBeginning, kATSUToTextEnd t.SetCGContext cg.Handle t.TransientFontMatching=true // must have! t.DrawText kATSUFromTextBeginning, kATSUToTextEnd,100,100 end if End EventHandler
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCF Plugin.




Links
MBS Xojo Plugins