This version of the module is deprecated: Use moonbitlang/pdflite instead
flowchart LR
Units[PdfUnit] --> Paper[PaperSize]
Paper --> PageBox[page MediaBox]
Point[Point2] --> Matrix[TransformMatrix]
Ops[TransformOp list] --> Matrix
Matrix --> PointOut[transformed point]///|
test "paper sizes and units are explicit" {
if @geometry.paper_a4.unit() != Millimetre {
fail("A4 is stored in millimetres")
}
if @geometry.unit_points(1.0, Inch) != 72.0 {
fail("one inch is 72 PDF points")
}
let landscape = @geometry.paper_a4.landscape()
if landscape.width() != 297.0 || landscape.height() != 210.0 {
fail("landscape swaps paper width and height")
}
}///|
test "transforms apply to points and render as PDF matrices" {
let moved = @geometry.transform_translate(5.0, -10.0).apply(
@geometry.point2(10.0, 20.0),
)
if moved.x != 15.0 || moved.y != 10.0 {
fail("translation should move the point")
}
inspect(
@geometry.transform_string_of_matrix(
@geometry.transform_translate(5.0, -10.0),
),
content="1, 0, 0, 1, 5, -10",
)
}pub(all) enum PdfPosition {
PdfPositionPosCentre(Double, Double)
PdfPositionPosLeft(Double, Double)
PdfPositionPosRight(Double, Double)
PdfPositionTop(Double)
PdfPositionTopLeft(Double, Double)
PdfPositionTopRight(Double, Double)
PdfPositionLeft(Double)
PdfPositionBottomLeft(Double, Double)
PdfPositionBottom(Double)
PdfPositionBottomRight(Double, Double)
PdfPositionRight(Double)
PdfPositionDiagonal
PdfPositionReverseDiagonal
PdfPositionCentre
} derive(Eq, ToJson, Debug)fn pdf_calculate_position(ignore_distance : Bool, text_width : Double, bounds : PdfRectangle, position : PdfPosition) -> PdfCalculatedPositionfn transform_append(after : ArrayView[TransformOp], before : ArrayView[TransformOp]) -> Array[TransformOp]fn transform_recompose_components(scale : Double, aspect : Double, rotation : Double, shear : Double, translate_x : Double, translate_y : Double) -> TransformMatrixInstall
Download zipByte-oriented PDF reading, writing, and manipulation toolkit for MoonBit.