17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.4 Matchboxes<br />

Matchboxes provide access to coordinates calculated by <strong>PDFlib</strong> as a result of placing<br />

some content on the page. Matchboxes are not defined with a dedicated function, but<br />

with the matchbox option in the function call which places the actual element, for example<br />

fit_textline( ) and fit_image( ). Matchboxes can be used for various purposes:<br />

> Matchboxes can be decorated, e.g. filled with color or surrounded by a frame.<br />

> Matchboxes can be used to automatically create one or more annotations with<br />

create_annotation( ).<br />

> Matchboxes define the height of a text line which will be fit into a box with fit_<br />

textline( ) or the height of a text fragment in a Textflow which will be decorated<br />

(boxheight option).<br />

> Matchboxes define the clipping for an image.<br />

> The coordinates of the matchbox and other properties can be queried with info_<br />

matchbox( ) to perform some other task, e.g. insert an image.<br />

For each element <strong>PDFlib</strong> will calculate the matchbox as a rectangle corresponding to the<br />

bounding box which describes the position of the element on the page (as specified by<br />

all relevant options). For Textflows and table cells a matchbox may consist of multiple<br />

rectangles because of line or row breaking.<br />

The rectangle(s) of a matchbox will be drawn before drawing the element to be<br />

placed. As a result, the element may obscure the effect of the matchbox border or filling,<br />

but not vice versa. In particular, those parts of the matchbox which overlap the area<br />

covered by an image are hidden by the image. If the image is placed with fitmethod=slice<br />

or fitmethod=clip the matchbox borders outside the image fitbox will be clipped as well.<br />

To avoid this effect the matchbox rectangle can be drawn using the basic drawing functions,<br />

e.g. rect( ), after the fit_image( ) call. The coordinates of the matchbox rectangle can<br />

be retrieved using info_matchbox( ) as far as the matchbox has been provided with a<br />

name in the fit_image( ) call.<br />

In the following sections some examples for using matchboxes are shown. For details<br />

about the functions which support the matchbox option list, see the <strong>PDFlib</strong> API<br />

Reference.<br />

8.4.1 Decorating a Textline<br />

Let’s start with a discussion of matchboxes in text lines. In fit_textline( ) the matchbox is<br />

the textbox of the supplied text. The width of the textbox is the text width, and the<br />

height is the capheight of the given font size, by default. To illustrate the matchbox size<br />

the following code fragment will fill the matchbox with blue background color (see Figure<br />

8.40a).<br />

String optlist =<br />

"font=" + normalfont + " fontsize=8 position={left top} " +<br />

"matchbox={fillcolor={rgb 0.8 0.8 0.87} boxheight={capheight none}}";<br />

p.fit_textline("Giant Wing Paper Plane", 2, 20, optlist);<br />

You can omit the boxheight option since boxheight={capheight none} is the default setting.<br />

It will look better if we increase the box height so that it also covers the descenders<br />

using the boxheight option (see Figure 8.40b).<br />

242 Chapter 8: Text and Table Formatting (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!