Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/RotatedTextProblem
Function:
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/RotatedTextProblem
This example is the version from Mon, 10th Feb 2013.
Project "RotatedTextProblem.rbp"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // We have a lot of text sitting in the EditField // that we want to print. What we need to // do now is let the user pick page setup information // as well as printer information. dim pagesetup as new PrinterSetup if not pagesetup.PageSetupDialog( self ) then // The user cancelled, so we should bail out return end // Get a Graphics object from the printer that // the user chooses dim printer as Graphics printer = OpenPrinterDialog( pagesetup, self ) // If the user cancelled that dialog, then we want // to bail out. if printer = nil then return // Good! The user decided to print. Let's get // all the information we need from the printer // and its setup object and pass it along to our // print function DoPrinting( printer, pagesetup ) End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim Astr as string g.ForeColor=&c00000000 g.DrawRect(1,1,g.Width-1,g.Width-1) g.DrawLine(g.Width/2,0,g.Width/2, g.Height) g.ForeColor=&c93939300 g.FillRect(0,0,g.width/2,g.Width/2) g.ForeColor=&c00000000 Astr="Printing Rotated Text" dim y as integer = g.Width/2 dim x as integer = g.Width/2 if CheckFix.Value then // calculate coordinates ourself if TargetCocoa then y = g.Height-y elseif TargetCarbon then y = self.Height-y-canvas1.top x = x + canvas1.Left end if g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, true) else // plugin auto mode is not always right due to missing information g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, false) end if y = g.Width*3/4 x = g.Width*3/4 if CheckFix.Value then if TargetCocoa then y = g.Height-y elseif TargetCarbon then y = self.Height-y-canvas1.top x = x + canvas1.Left end if g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, true) else g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, false) end if End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control CheckFix Inherits CheckBox
ControlInstance CheckFix Inherits CheckBox
EventHandler Sub Action() canvas1.Invalidate End EventHandler
End Control
Protected Sub BeginPrinting(g as Graphics, pagesetup as PrinterSetup) // We do all of our printing setup here. In this // case, we create a proper StyledTextPrinter object // so that we can use it when doing all of our printing. // This function gets called once at the beginning // of each print job 'mStp = EditField1.StyledTextPrinter( g, pagesetup.Width ) End Sub
Protected Sub DoPrinting(g as Graphics, pagesetup as PrinterSetup) if pagesetup = nil or g = nil then return // We have to watch out for a few things because // REALbasic doesn't take care of these issues for // us. 1) Page ranges -- the user can specify a // range of pages they want to print. We want to // eat any pages they didn't request. 2) Copies -- // the user may want multiple copies of the output, // with the page range information applying to // each copy. 3) You'd think we have to watch out // for landscaping, but we really don't. We just print // based on the information given to us since the // width and the height of the pagesetup object // will automatically reflect the proper page information. // Print the proper number of copies by looping // thru and passing the problem off to another // function. dim i, copies as Integer copies = g.Copies for i = 0 to copies - 1 PrintOneCopy( g, pagesetup ) next End Sub
Protected Sub EndPrinting() // This function gets called once at the end of // each print job. We just do general cleanup here. mStp = nil End Sub
Protected Sub PrintOneCopy(g as Graphics, pagesetup as PrinterSetup) // We want to print one copy of the information. // At this stage, we just need to worry about // style (landscape vs portrait) and the page // range we need to print for. // The basic idea is that we are given a graphics // object that is X by Y pixels wide and a set // of information (stored in our EditField) that // needs to be printed. We will figure out just // how much data can be printed on a single // line and print that. If the page is going to // be eaten, then so be it. We simply won't call // Graphics.NextPage and instead call Graphics.ClearRect // to wipe the page clean. This way, only the proper // pages that the user asked for get printed. // Before we get started, we want to initialize // some information for the print worker BeginPrinting( g, pagesetup ) // We will pass the work off to one more level // to actually do the printing to the Graphics // object. This level's job is to determine which // pages get used and which ones get wiped. dim currentPageNumber as Integer = 1 while PrintSomeInformation( g, pagesetup ) // If we printed something to the printer's // graphics context, then we should check // to see if it's one of the pages we // care about. We don't call NextPage if // this was the LastPage because the Graphics // object will print the page automatically when // it gets set to nil if currentPageNumber >= g.FirstPage and _ currentPageNumber < g.LastPage then // This is a page we want to print, so let's // shoot it off to the printer g.NextPage elseif currentPageNumber = g.LastPage then // We're done printing, so we can exit // without calling NextPage exit else // This was a page we don't want to print, so // we'll clear the Graphics context g.ClearRect( 0, 0, g.Width, g.Height ) end // Advance the page number currentPageNumber = currentPageNumber + 1 wend // We're done printing this copy of the information! // Let's let the worker know that we're done EndPrinting End Sub
Protected Function PrintSomeInformation(g as Graphics, pagesetup as PrinterSetup) As Boolean // Here is where the actual work of formatting // and doing the printing happens. The job of this // function is to print as much information as it // can to the page. If more data need to be printed, // then we return true. If we're done printing // then it should return false to signal the end of // this copy // What's neat is that we don't need to do anything // special to accomodate landscaped printing. The // printer already provides the functionality, we just // need to account for the width and height of the // page. // The StyledTextPrinter was setup during BeginPrinting // so that we can just use it here as one single object // instead of always needing to recreate it. dim Astr as string g.ForeColor=&c00000000 g.DrawRect(1,1,g.Width-1,g.Width-1) g.DrawLine(g.Width/2,0,g.Width/2, g.Height) g.ForeColor=&c93939300 g.FillRect(0,0,g.width/2,g.Width/2) g.ForeColor=&c00000000 Astr="Printing Rotated Text" dim y as integer = g.Width/2 dim x as integer = g.Width/2 if CheckFix.Value then if TargetCocoa then y = g.Height-y - pagesetup.PageTop*2 + g.TextHeight/2 elseif TargetCarbon then y = g.Height-y end if g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, true) else g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, false) end if x = g.Width *3 /4 y = g.Width *3 /4 if CheckFix.Value then if TargetCocoa then y = g.Height-y - pagesetup.PageTop*2 + g.TextHeight/2 elseif TargetCarbon then y = g.Height-y end if g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, true) else g.DrawRotatedTextMBS(0, Astr, x, y, True, 1.0, false) end if // If we're done printing, then we will return false, // otherwise we'll return true so we can keep printing // the next piece of information. return false End Function
Property Protected mStp As StyledTextPrinter
This property is used to render the editfield with all its style information directly to the printer context.
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"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class App Inherits Application
End Class
End Project

Feedback, Comments & Corrections

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




Links
MBS FileMaker blog