Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/ATS/ATSUI Text rendering in Overlay Window
Required plugins for this example: MBS MacCF Plugin, MBS MacCG Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/ATS/ATSUI Text rendering in Overlay Window
This example is the version from Sun, 17th Mar 2012.
Project "ATSUI Text rendering in Overlay Window.rbp"
Filetype image/jpeg
End FileTypes
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileSave = "Save"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() CreateWindow End EventHandler
Protected Sub CreateWindow() if TargetMacOS then // ok else MsgBox "This example requires Mac OS X!" quit end if w=new MyOverlayWindowMBS 'w.EatMouseEvents=true // required before Create to be successfull on Mac OS X 10.1.5 or earlier if w.Create(200,200,400,500)<>0 then MsgBox "Can't create overlay window!" else w.Show w.drawwindow end if End Sub
Property Protected w As MyOverlayWindowMBS
End Class
Module Constants
Const TheText = "Apple Reports First Quarter Results\rRevenue Increases 36 Percent Year-Over-Year \r\rCUPERTINO, California—January 14, 2004—Apple® today announced financial results for its fiscal 2004 first quarter ended December 27, 2003. For the quarter, the Company posted a net profit of $63 million, or $.17 per diluted share. These results compare to a net loss of $8 million, or $.02 per diluted share, in the year-ago quarter. Revenue for the quarter reached a four-year high of $2.006 billion, up 36 percent from the year-ago quarter. Gross margin was 26.7 percent, down from 27.6 percent in the year-ago quarter. International sales accounted for 44 percent of the quarter’s revenue.\r\rThe quarter’s results include an after-tax investment gain of $3 million which increased earnings per diluted share by $.01.\r\rApple shipped 829 thousand Macintosh® units during the quarter, up 12 percent from the year-ago quarter, as well as 733 thousand iPod® units, up 235 percent from the year-ago quarter.\r\r“It was an outstanding quarter for Apple, with double-digit unit and revenue growth and over 730,000 iPods sold,” said Steve Jobs, Apple’s CEO. ""We’re kicking off 2004 with strong momentum, especially for Mac OS X, which is now used by almost 40 percent of our installed base, iPod and the iTunes Music Store, which has a 70 percent share of the legal music download market.”\r\r“We are very pleased to have exceeded our revenue and profit targets for the first quarter,” said Fred Anderson, Apple’s CFO. “Continued strong asset management enabled us to increase cash by $225 million to just under $4.8 billion. Looking ahead to the second quarter of fiscal 2004, we expect our third consecutive quarter of year-over-year double-digit growth in both revenue and earnings, with revenue of about $1.8 billion and earnings per diluted share of $.08 to $.10.”"
End Module
Module DrawCode
Sub Draw(cg as cgcontextMBS, width as integer, height as integer) dim s1,s2,s3 as ATSUStyleMBS dim t as ATSUTextLayoutMBS dim a as string dim TextBefore as Double dim TextAfter as Double dim Ascent as Double dim Descent as Double dim endLineOffset,offset as integer dim linewidth,linecount as integer dim m as MemoryBlock dim lineheight as double dim p,i as integer dim x,y as Double dim lineend,linestart as integer dim LineBreaks(0) as integer dim LineHeights(0) as integer const kATSUFromTextBeginning=-1 const kATSUToTextEnd=-1 cg.SetRGBFillColor 0,0,0,1 // black cg.SetRGBStrokeColor 0,0,0,1 // black a=TheText a=UnicodeStringMBS(a) s1=new ATSUStyleMBS s1.Create s1.Size=18 s1.bold=true s2=new ATSUStyleMBS s2.Create s2.Size=14 s2.bold=true s3=new ATSUStyleMBS s3.Create s3.Size=12 t=new ATSUTextLayoutMBS t.Create t.SetTextPointerLocation a,kATSUFromTextBeginning,kATSUToTextEnd,len(a) t.SetRunStyle s1,kATSUFromTextBeginning, 36 t.SetRunStyle s2,36, 80 t.SetRunStyle s3,80, kATSUToTextEnd linewidth=width-20 // measure and break each line, thus setting a soft line break that we'll grab back later while offset<len(a) endLineOffset=t.BreakLine(offset,linewidth,true) // it could be that the line width is so narrow that even a single character won't fit. // in that case, ATSUBreakLine returns noErr but endLineOffset returns equal to offset. // if that's the case, let's break out... if endLineOffset=offset then exit end if t.MeasureText offset,endLineOffset-offset,TextBefore, TextAfter, Ascent, Descent // let's get ascent & descent to calculate the line height later. LineBreaks.Append endLineOffset lineheights.Append Descent+Ascent offset=endLineOffset linecount=linecount+1 wend // Where to draw to t.SetCGContext cg.Handle x=2 y=Height-lineheights(1) lineStart=0 for i=1 to linecount lineend=LineBreaks(i) lineheight=lineheights(i) t.DrawText linestart, lineend-lineStart,x,y+Descent y=y-lineheight lineStart = lineEnd next End Sub
End Module
Class MyOverlayWindowMBS Inherits OverlayWindowMBS
EventHandler Sub WindowBoundsChanged() drawwindow End EventHandler
Sub DrawRoundRect(ct As CGContextMBS, x as integer, y as integer, w as integer, h as integer, arcx as integer, arcy as integer, filled as boolean) // code adapted from EasyOverlay example project dim yy, xp, yp As integer yy=height-h-y ct.beginPath xp=x+arcX yp=yy ct.MoveToPoint xp,yp //goto TopLeft xp=xp+w - 2*arcx ct.AddLineToPoint xp,yp // top line xp=xp+arcx ct.AddQuadCurveToPoint xp, yp, xp, yp+arcy // TopRight corner yp=yp+h-arcy ct.AddLineToPoint xp,yp // right line yp=yp+arcy ct.AddQuadCurveToPoint xp, yp, xp-arcx, yp // Bottom/Right Corner xp=xp-w+arcx ct.addLineToPoint xp, yp //bottom line xp=x yp=yp-arcy ct.AddQuadCurveToPoint xp, yp+arcy, xp, yp //BottomLeft corner yp=yy+arcy ct.addLineToPoint xp,yp // left line ct.AddQuadCurveToPoint x, yy, x+arcX, yy // TopLeft corner if filled then ct.fillPath else ct.StrokePath end if End Sub
Sub drawwindow() dim c as CGContextMBS c=self.Context c.ClearRect CGMakeRectMBS(0,0,Width,Height) c.SetRGBFillColor 1.0,0.5,0.5,0.5 DrawRoundRect c,0,0,Width,Height,10,10,true draw c, Width, Height c.Flush Flush End Sub
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS FileMaker tutorial videos