Satimage Previous
PDF drawing
Home Documentation Smile The graphic library PDF drawing   Dictionary of the Graphic Library
Opening and closing a graphic

Opening a new graphic basically consists in declaring where the drawing will take place. The simplest is to use the Default graphic window, but you can also display a graphic on the fly in a graphic window, in a view, in a dialog, or add graphics to a SmileLab data plot.

Note: To use Smile's graphic library, you have to write a script, for example in an AppleScript terminal.

All graphic commands must be encapsulated between opening and closing graphic commands: the opening commands that you can use are BeginFigure, BeginFrontFigure, BeginPDF and BeginContext. The respective closing commands are EndFigure, EndFrontFigure, EndPDF and EndContext.

  • To use a defaut graphic window, use BeginFigure(0) ... EndFigure() (using zero for the BeginFigure's parameter). If the default graphic window doesn't exist, it will be created on BeginFigure(0). The graphic will be updated on EndFigure().
    set x to 500
    BeginFigure(0)
    CirclePath({x / 2, x / 2}, x / 10)
    DrawPath(2)
    EndFigure()
  • To draw in the PDF contents of an existing graphic window or view, use BeginFigure(w) or BeginFrontFigure(w), where w is a reference to the window or to the view. The graphic commands calls must follow, and end with EndFigure() or EndFrontFigure() to have the graphic being drawn effectively. graphic window and chart views have two PDF layers: BeginFigure ... EndFigure wrappers draw on the background layer, and BeginFrontFigure ... EndFrontFigure wrappers draw on the foreground wrapper. SmileLab plots are drawn between the two PDF Layers, so that you can customize its display with the graphic library.

    set the_ppties to {pagewidth:4 * 72, pageheight:4 * 72, name:"4 inches square"}
    set the_gw to make new graphic window with properties the_ppties
    BeginFigure(the_gw)
    -- graphical commands go here
    EndFigure()
  • To produce a PDF record without specifically displaying it in an object of Smile, open the graphic with BeginPDF. You have to pass the size of the PDF. After the graphical commands, use EndPDF() to get the PDF record - a string starting with the four characters %PDF. The quantity that EndPDF() returns is a valid PDF record, that you can directly store as a PDF file, or load into an object of Smile which supports PDF (for example, a PDF holder in a dialog).

    set x to 400
    BeginPDF({0, 0, x, x / 1.33})
    SetTextFont("Arial")
    SetTextSize(x / 10)
    TextMoveTo({x / 2, x / 2.66})
    DrawString("[h]My 1^{st} PDF file!")
    set the_pdf to EndPDF()
    -- make a new file on the desktop, write the PDF record in it, then open the file
    tell application "Finder" to set the_file to (make new file at desktop with properties {name:(make new name) & ".pdf" }) as alias
    write the_pdf to the_file
    tell application "Preview" to open the_file


    Import script
The graphic commands
The graphic library provides graphic commands to draw patterns, images or texts, or to change the draw settings. The main commands are defined in the Graphic library dictionary. If you want to make geometrical computations, you may also use commands defined in the dictionary of the Geometry.osax scripting addition. You can consult dictionaries from the File ▸ Open a dictionary menu.

Note: The drawing text commands support a specific syntax to draw special characters documented on this page.
Version française
Copyright ©2008 Paris, Satimage