fltk.device

Device abstraction classes for advanced drawing operations.

This module provides classes for drawing to various output devices such as PostScript files for printing and PDF generation.

Example:

import std.stdio : File;
import fltk.device;

// Create a PostScript output file
auto file = File("output.ps", "wb");
auto dev = new PostScriptFileDevice();

// Start a print job with A4 paper in portrait orientation
if (dev.startJob(file, 1, PageFormat.A4, PageLayout.PORTRAIT)) {
    dev.startPage();
    // Draw widgets here using dev.printWidget()
    dev.endPage();
    dev.endJob();
}

Types 3

Standard page formats for printing.

These correspond to common paper sizes used worldwide.

A0 = 0A0 format (841 × 1189 mm)
A1 = 1A1 format (594 × 841 mm)
A2 = 2A2 format (420 × 594 mm)
A3 = 3A3 format (297 × 420 mm)
A4 = 4A4 format (210 × 297 mm)
A5 = 5A5 format (148 × 210 mm)
A6 = 6A6 format (105 × 148 mm)
A7 = 7A7 format (74 × 105 mm)
A8 = 8A8 format (52 × 74 mm)
A9 = 9A9 format (37 × 52 mm)
B0 = 10B0 format (1000 × 1414 mm)
B1 = 11B1 format (707 × 1000 mm)
B2 = 12B2 format (500 × 707 mm)
B3 = 13B3 format (353 × 500 mm)
B4 = 14B4 format (250 × 353 mm)
B5 = 15B5 format (176 × 250 mm)
B6 = 16B6 format (125 × 176 mm)
B7 = 17B7 format (88 × 125 mm)
B8 = 18B8 format (62 × 88 mm)
B9 = 19B9 format (44 × 62 mm)
B10 = 20B10 format (31 × 44 mm)
C5E = 21C5 envelope (162 × 229 mm)
DLE = 22DL envelope (110 × 220 mm)
EXECUTIVE = 23Executive (184 × 267 mm)
FOLIO = 24Folio (210 × 330 mm)
LEDGER = 25Ledger (432 × 279 mm)
LEGAL = 26Legal (216 × 356 mm)
LETTER = 27Letter (216 × 279 mm)
TABLOID = 28Tabloid (279 × 432 mm)
ENVELOPE = 29Envelope
MEDIA = 0x1000Custom media

Page layout/orientation for printing.

PORTRAIT = 0Portrait orientation (vertical)
LANDSCAPE = 0x100Landscape orientation (horizontal)
REVERSED = 0x200Reversed orientation
ORIENTATION = 0x300Orientation mask

A drawing surface that outputs PostScript to a file.

This class provides non-interactive PostScript output, suitable for generating print files, PDFs (via ps2pdf), or batch printing operations. Unlike the interactive Printer class, this writes directly to a FILE stream without showing any dialogs.

Example:

import core.stdc.stdio : fopen, fclose;
auto dev = new PostScriptFileDevice();
auto file = fopen("output.ps", "wb");
if (file !is null) {
    if (dev.startJob(file, 1)) {
        dev.startPage();
        // Drawing operations...
        dev.endPage();
        dev.endJob();
    }
    fclose(file);
}

Methods
bool startJob(void * output, int pagecount, PageFormat format = PageFormat.A4, PageLayout layout = PageLayout.PORTRAIT) @trustedStarts a print job to a C FILE stream.
bool startPage() @trustedStarts a new page in the document.
bool endPage() @trustedEnds the current page.
void endJob() @trustedEnds the print job and finalizes the PostScript output.
bool printableRect(out int w, out int h) @trustedGets the dimensions of the printable area.
void margins(out int left, out int top, out int right, out int bottom) @trustedGets the page margins.
void getOrigin(out int x, out int y) @trustedGets the current drawing origin.
void setOrigin(int x, int y) @trustedSets the drawing origin.
void scale(float scaleX, float scaleY = 0) @trustedSets the scale factor for drawing operations.
void rotate(float angle) @trustedRotates subsequent drawing operations.
void translate(int x, int y) @trustedTranslates the drawing origin.
void untranslate() @trustedUndoes the last translate() operation.
void printWidget(Widget widget, int deltaX = 0, int deltaY = 0) @trustedPrints a widget to the PostScript output.
void printWindow(Window win, int xOffset = 0, int yOffset = 0) @trustedPrints a window with its decorations to the PostScript output.
void setCurrent() @trustedMakes this device the current drawing target.
PostScriptFileDevicePtr postScriptFileDevicePtr() @trusted nothrow @nogcReturns the underlying handle for low-level operations.
Constructors
this()Creates a new PostScript file device.
Destructors