#! perl use strict; use warnings; use utf8; package Text::Layout; use Carp; our $VERSION = "0.039"; =head1 NAME Text::Layout - Pango style markup formatting This module will cooperate with PDF::API2, PDF::Builder, Cairo, and Pango. =head1 SYNOPSIS Text::Layout provides methods for Pango style text formatting. Where possible the methods have identical names and (near) identical behaviour as their Pango counterparts. See L. The package uses Text::Layout::FontConfig (included) to organize fonts by description. If module HarfBuzz::Shaper is installed, Text::Layout can use it for text shaping. Example, using PDF::API2 integration: use PDF::API2; # or PDF::Builder use Text::Layout; # Create a PDF document. my $pdf = PDF::API2->new; # or PDF::Builder->new $pdf->default_page_size("a4") # ISO A4 # Set up page and get the text context. my $page = $pdf->page; my $ctx = $page->text; # Create a markup instance. my $layout = Text::Layout->new($pdf); # This example uses PDF corefonts only. Text::Layout::FontConfig->register_corefonts; $layout->set_font_description(Text::Layout::FontConfig->from_string("times 40")); $layout->set_markup( q{The quick brown fox} ); # Center text. $layout->set_width(595); # width of A4 page $layout->set_alignment("center"); # Render it. $layout->show( 0, 600, $ctx ); $pdf->save("out.pdf"); All PDF::API2 graphic and text methods can still be used, they won't interfere with the layout methods. =head1 NOTES FOR PDF::API2/Builder USERS =head2 Baselines PDF::API2 and PDF::Builder render texts using the font baseline as origin. This module typesets text in an area of possibly limited width and height. The origin is the top left of this area. Currently this area contains only a single line of text. This will change in the future when line breaking and paragraph formatting is implemented. PDF::API2 and PDF::Builder coordinates have origin bottom left. This module produces information with respect to top left coordinates. =head1 IMPORTANT NOTES FOR PANGO USERS =head2 Coordinate system Pango, layered upon Cairo, uses a coordinate system that starts off top left. So for western text the direction is increasing I and increasing I. PDF::API2 uses the coordinate system as defined in the PDF specification. It starts off bottom left. For western text the direction is increasing I and Bcreasing I. =head1 Pango Conformance Mode Text::Layout can operate in one of two modes: I (enabled by default), and I. The desired mode can be selected by calling the method set_pango_scaling(). =head2 Pango coordinates Pango uses two device coordinates units: Pango units and device units. Pango units are 1024 (C) times the device units. Several methods have two variants, e.g. get_size() and get_pixel_size(). The pixel-variant uses device units while the other variant uses Pango units. In I, this module assumes no scaling. All units are PDF device units (1/72 inch). =head2 Pango device units Device units are used for font rendering. Pango device units are 96dpi while PDF uses 72dpi. In I this is ignored. E.g. a C font will be of equal size in the two systems, In I you would need to specify a font size of C<15360> to get a 20pt font. =head1 SUPPORTED MARKUP Text::Layout recognizes most of the Pango markup as provided by the Pango library version 1.50 or newer. However, not everything is supported. =head2 Span attributes =over 8 =item font="I" font_desc="I" Specifies a font to be used, e.g. C. =item font_face="I" face="I" Specifies a font family to be used. =item font_family="I" Same as font_face="I". =item size=I size=Ipt size=I% Font size in 1024ths of a point (conformance mode), or in points (e.g. '12.5pt'), or a percentage (e.g. '200%'), or one of the relative sizes 'smaller' or 'larger'. Note that in Pango conformance mode, the actual font size is 96/72 larger. So C<"45pt"> gives a 60pt font. =item style="I