exampleTextStyles
   "Show the functionality from the PDFPrinter. Here we print texts
    with different fonts, styles and sizes on a windows plattform"
   "In order to run the example it may be neccessary to change the
    TrueType font name if the registered font is not installed in your
    Windows environment"
   "PDFPrinter exampleTextStyles"

   | printer boldStyle normalStyle |
   PDFPrinterFontTrueType fontLocation: 'C:\WINDOWS\FONTS'.
   PDFPrinterFontTrueType addFont: 'Monotype Corsiva' storedIn: 'MTCORSVA.TTF'.
   printer := Printer startPrintJobNamed: 'TextStyles.pdf'.
   printer printBlock:
      [| gc device top styles text fonts titles font |
      device := printer graphicsDevice.
      gc := printer graphicsContext.
      gc paint: ColorValue black.

      "Define the font and style for the sub titles"
      (font := FontDescription new pixelSize: 14)
            family: 'helvetica';
            boldness: 1.0;
            italic: false.
      boldStyle := TextAttributes defaultFontQuery: font copy.

      "Define the font and style for the descriptions"
      (font := FontDescription new pixelSize: 12)
            family: 'helvetica';
            boldness: 0.5;
            italic: false.
      normalStyle := TextAttributes defaultFontQuery: font copy.

      "Print the title line"
      text := 'The quick brown fox jumps over the lazy dog'.
      (font := FontDescription new pixelSize: 18)
            family: 'helvetica';
            boldness: 1.0;
            italic: false.
      (ComposedText
         withText: 'PDFPrinter functionality (Text Styles)'
         style: (TextAttributes defaultFontQuery: font copy))
            newGraphicsDevice: device;
            displayOn: gc at: 100 @ 20.

      (ComposedText
         withText: 'Text styles and Fonts (Base14 - Build in Fonts)'
         style: boldStyle)
            newGraphicsDevice: device;
            displayOn: gc at: 20 @ 50.

         "We firts print the embedded base 14 fonts that have
          to be supported by all PDF viewer"
         top := 50.
         fonts := #('helvetica' 'times' 'courier').
         titles := #('Helvetica (sans serif)' 'Times (serif)' 'Courier').
         styles := Array with: true -> false with: false -> true with: true -> true.
         1 to: 3 do: [:index |
            styles do: [:anAssociation |
               | fontName |
               top := top + 20.
               fontName := titles at: index.
               anAssociation key
                  ifTrue: [fontName := fontName , ' bold'.
                         anAssociation value ifTrue: [fontName := fontName , ' and italic']]
                  ifFalse:[anAssociation value ifTrue: [fontName := fontName , ' italic']].

               (ComposedText withText: fontName style: normalStyle)
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top.
               top := top + 16.

               (font := FontDescription new pixelSize: 12)
                  family: (fonts at: index);
                  boldness: (anAssociation key ifTrue: [1.0] ifFalse: [0.5]);
                  italic: anAssociation value.
               (ComposedText
                  withText: text
                  style: (TextAttributes defaultFontQuery: font copy))
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top].
            top := top + 10].
         top := top + 20.
         (ComposedText
            withText: 'Text styles and Fonts (Loaded TrueType Fonts)'
            style: boldStyle)
               newGraphicsDevice: device;
               displayOn: gc at: 20 @ top.

         "Print some text with a loaded TrueType font in different colors"
         #('Black' 'Red' 'Green' 'Blue') do: [:color |
            top := top + 20.
            (ComposedText
               withText: 'Monotype Corsiva' , ' in ' , color
               style: normalStyle)
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top.

            top := top + 16.
            gc paint: (ColorValue perform: color asLowercase asSymbol).
            (font := FontDescription new pixelSize: 12)
                  family: 'monotype corsiva';
                  boldness: 0.5;
                  italic: false.
            (ComposedText
               withText: text
               style: (TextAttributes defaultFontQuery: font copy))
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top].

         "The last block prints the text in different sizes"
         gc paint: ColorValue black.
         top := top + 30.
         (ComposedText withText: 'Text sizes' style: boldStyle)
            newGraphicsDevice: device;
            displayOn: gc at: 20 @ top.

         #(6 9 12 14 18 24) do: [:size |
            top := top + 20.
            (ComposedText
               withText: 'Times size: ' , size printString
               style: normalStyle)
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top.

            top := top + size.
            (font := FontDescription new pixelSize: size)
                  family: 'times';
                  boldness: 0.5;
                  italic: false.
            (ComposedText
               withText: text
               style: (TextAttributes defaultFontQuery: font copy))
                  newGraphicsDevice: device;
                  displayOn: gc at: 20 @ top]]