Class: EideticPDF::DocumentWriter
- Inherits:
-
Object
- Object
- EideticPDF::DocumentWriter
- Defined in:
- lib/epdfdw.rb
Instance Attribute Summary collapse
-
#bullets ⇒ Object
readonly
:nodoc:.
-
#catalog ⇒ Object
readonly
:nodoc:.
-
#encodings ⇒ Object
readonly
:nodoc:.
-
#file ⇒ Object
readonly
:nodoc:.
-
#fonts ⇒ Object
readonly
:nodoc:.
-
#images ⇒ Object
readonly
:nodoc:.
-
#in_page ⇒ Object
readonly
Returns the value of attribute in_page.
-
#pages ⇒ Object
readonly
:nodoc:.
-
#resources ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#arc(x, y, r, start_angle, end_angle, move_to0 = false) ⇒ Object
Draw an arc with origin
x, y
and radiusr
fromstart_angle
toend_angle
degrees. -
#arch(x, y, r1, r2, start_angle, end_angle, options = {}, &block) ⇒ Object
Draw an arch with origin
x, y
fromstart_angle
to end_angle degrees. -
#auto_path ⇒ Object
Returns current status of auto_path.
-
#bullet(name, options = {}, &block) ⇒ Object
Given a block, defines a named bullet.
-
#canvas_height ⇒ Object
page_width
excluding left and right margins. -
#canvas_width ⇒ Object
page_height
excluding top and bottom margins. -
#circle(x, y, r, options = {}, &block) ⇒ Object
Draw a circle with center
x, y
and radiusr
. -
#clip(options = {}, &block) ⇒ Object
Use current path as a clipping boundary for anything drawn within the supplied block.
-
#close ⇒ Object
Close any open pages, preparing the document for rendering to PDF.
-
#close_page ⇒ Object
Close the current open page.
-
#cur_page ⇒ Object
:nodoc:.
-
#curve(x0, y0, x1, y1, x2, y2, x3, y3) ⇒ Object
Draw a cubic Bezier curve from
(x0, y0)
to(x3, y3)
with control points<x1, y1>
and(x2, y2)
. -
#curve_points(points) ⇒ Object
Draw a series of cubic Bezier curves.
-
#doc(options = {}) {|_self| ... } ⇒ Object
Open the document for writing and yield to the block given before calling
close
. -
#ellipse(x, y, rx, ry, options = {}) ⇒ Object
Draw an ellipse with foci (
x, y
) and (x, y
) and radiusr
. -
#fill ⇒ Object
Fill current path (begun by
path
method) and resumeauto_path
. -
#fill_and_stroke ⇒ Object
Fill and stroke current path (begun by
pat
method) and resumeauto_path
. -
#fill_color(color = nil) ⇒ Object
Set fill color, returning previous fill color.
-
#font(name = nil, size = nil, options = {}) ⇒ Object
Set font, returning previous font.
-
#font_color(color = nil) ⇒ Object
Set font color, returning previous font color.
-
#font_encoding(encoding = nil) ⇒ Object
Set font encoding, returning previous font encoding.
-
#font_size(size = nil) ⇒ Object
Set font size, returning previous font size.
-
#font_style(style = nil) ⇒ Object
Set font style, returning previous font style.
-
#height(text = '', units = nil) ⇒ Object
Returns height of a line or array of lines, including external leading as determined by
line_height
. -
#indent(value = nil, absolute = false) ⇒ Object
Set horizontal indentation.
-
#initialize ⇒ DocumentWriter
constructor
Instantiate a new DocumentWriter object.
-
#jpeg?(image) ⇒ Boolean
Returns
true
if image is a buffer beginning with a JPEG signature. -
#jpeg_dimensions(image) ⇒ Object
Returns a tuple (array) of image dimensions of the form [width, height, components, bits_per_component].
-
#line(x, y, angle, length) ⇒ Object
Draw a line from point
(x, y)
to a pointlength
units distant atangle
degrees. -
#line_cap_style(style = nil) ⇒ Object
Set the shape to be used at the ends of lines.
-
#line_color(color = nil) ⇒ Object
Set line color, returning previous line color.
-
#line_dash_pattern(pattern = nil) ⇒ Object
Set the pattern of dashes and gaps used to draw lines.
-
#line_height(height = nil) ⇒ Object
Set line height as used by methods like
paragraph
that display multiple lines of text. -
#line_to(x, y) ⇒ Object
Draw a line from the current location to point
(x, y)
. -
#line_width(value = nil, units = nil) ⇒ Object
Set line width used when stroking paths.
-
#load_image(image_file_name, stream = nil) ⇒ Object
:nodoc:.
-
#margin_bottom ⇒ Object
Returns bottom margin as set by
margins
method. -
#margin_left ⇒ Object
Returns left margin as set by
margins
method. -
#margin_right ⇒ Object
Returns right margin as set by
margins
method. -
#margin_top ⇒ Object
Returns top margin as set by
margins
method. -
#margins(*margins) ⇒ Object
Set top, right, bottom and left margins.
-
#move_by(dx, dy) ⇒ Object
Move the pen to a new location relative to the current location.
-
#move_to(x, y) ⇒ Object
Move pen to point
(x, y)
. -
#named_colors ⇒ Object
Returns hash of named colors consisting of (name, color) pairs.
-
#new_line(count = 1) ⇒ Object
Move pen down one or more lines and back to current indent.
-
#new_page(options = {}) ⇒ Object
Close the current page and begin a new page with the specified options.
-
#next_seq ⇒ Object
:nodoc:.
-
#open(options = {}) ⇒ Object
Open the document for writing.
-
#open_page(options = {}) ⇒ Object
Open a page for writing.
-
#page(options = {}) {|cur_page| ... } ⇒ Object
Open a page for writing and yield to the block given before calling
close_page
. -
#page_height ⇒ Object
Returns page height in current units.
-
#page_width ⇒ Object
Returns page width in current units.
-
#paragraph(text, options = {}) ⇒ Object
Wrap
text
and render with the followingoptions
. -
#paragraph_xy(x, y, text, options = {}) ⇒ Object
Move to
(x, y)
and render paragraph. -
#path(options = {}, &block) ⇒ Object
Turn off auto_path.
-
#pen_pos(x = nil, y = nil) ⇒ Object
Move pen to point
(x, y)
likemove_to
, returning previous location. -
#pie(x, y, r, start_angle, end_angle, options = {}) ⇒ Object
Draw a pie-shaped wedge with origin
x, y
and radiusr
fromstart_angle
toend_angle
degrees. -
#points_for_arc(x, y, r, start_angle, end_angle) ⇒ Object
Returns array of
Location
structs for arc, suitable for feeding tocurve_points
method. -
#points_for_circle(x, y, r) ⇒ Object
Returns array of
Location
structs for circle, suitable for feeding tocurve_points
method. -
#points_for_ellipse(x, y, rx, ry) ⇒ Object
Returns array of
Location
structs for ellipse, suitable for feeding tocurve_points
method. -
#points_for_polygon(x, y, r, sides, options = {}) ⇒ Object
Returns array of
Location
structs representing the vertices of a polygon. -
#polygon(x, y, r, sides, options = {}) ⇒ Object
Draw a polygon with origin
(x, y)
, radiusr
and the specified number ofsides
. -
#print(text, options = {}, &block) ⇒ Object
Print text, starting from the current position.
-
#print_image(data, x = nil, y = nil, width = nil, height = nil) ⇒ Object
Display graphic (currently only JPEG is supported) from disk (or network, if open-uri library is loaded) and display at the specified location.
-
#print_image_file(image_file_name, x = nil, y = nil, width = nil, height = nil) ⇒ Object
Load graphic file (currently only JPEG is supported) from disk (or network, if open-uri library is loaded) and display at the specified location.
-
#print_link(s, uri) ⇒ Object
:nodoc:.
-
#print_xy(x, y, text, options = {}, &block) ⇒ Object
Move to
(x, y)
and print text. -
#puts(text = '', options = {}, &block) ⇒ Object
Print one or more lines of text before moving to the next line, as specified by
indent
. -
#puts_xy(x, y, text, options = {}, &block) ⇒ Object
Move to
(x, y)
and print one or more lines of text indented tox
. -
#rectangle(x, y, width, height, options = {}) ⇒ Object
Draw a rectangle with the specified
width
andheight
and its top, left corner at(x, y)
. -
#rotate(angle, x, y, &block) ⇒ Object
Rotate anything drawn within the supplied block
angle
degrees around origin(x, y)
. - #scale(x, y, scale_x, scale_y, &block) ⇒ Object
-
#star(x, y, r1, r2, points, options = {}) ⇒ Object
Draw a star with origin
(x, y)
, outer radiusr1
, inner radiusr2
and the specified number ofsides
. -
#stroke ⇒ Object
Stroke current path (begun by
path
method) and resumeauto_path
. -
#tab(&block) ⇒ Object
Move right to next horizontal tab.
-
#tabs(tabs = nil) ⇒ Object
Set horizontal tabs using an array of numbers or a comma-delimited string.
-
#text_ascent(units = nil) ⇒ Object
Returns text ascent, based on the current font.
-
#text_height(units = nil) ⇒ Object
Returns text height, based on the current font, excluding external leading.
-
#to_s ⇒ Object
Render document to PDF and return as a binary string.
-
#truetype_font_names ⇒ Object
:nodoc:.
-
#type1_font_names ⇒ Object
Returns an array of font names, including weight and style, from the (local) fonts directory.
-
#underline(underline = nil) ⇒ Object
Set new underline status, returning previous status.
-
#units(units = nil) ⇒ Object
Set units measurements are to be specified in.
-
#v_text_align(vta = nil) ⇒ Object
Set vertical text alignment.
-
#vtab(&block) ⇒ Object
Move down to next vertical tab.
-
#vtabs(tabs = nil) ⇒ Object
Set vertical tabs using an array of numbers or a comma-delimited string.
-
#width(text) ⇒ Object
Returns width of a string as rendered using the current font.
-
#wrap(text, length) ⇒ Object
Breaks text into tokens and reassembles into array of strings, each one not exceeding
length
.
Constructor Details
#initialize ⇒ DocumentWriter
Instantiate a new DocumentWriter object. Document is NOT open for writing at this point.
26 27 28 29 30 31 |
# File 'lib/epdfdw.rb', line 26 def initialize @fonts = {} @images = {} @encodings = {} @bullets = {} end |
Instance Attribute Details
#bullets ⇒ Object (readonly)
:nodoc:
22 23 24 |
# File 'lib/epdfdw.rb', line 22 def bullets @bullets end |
#catalog ⇒ Object (readonly)
:nodoc:
21 22 23 |
# File 'lib/epdfdw.rb', line 21 def catalog @catalog end |
#encodings ⇒ Object (readonly)
:nodoc:
22 23 24 |
# File 'lib/epdfdw.rb', line 22 def encodings @encodings end |
#file ⇒ Object (readonly)
:nodoc:
21 22 23 |
# File 'lib/epdfdw.rb', line 21 def file @file end |
#fonts ⇒ Object (readonly)
:nodoc:
22 23 24 |
# File 'lib/epdfdw.rb', line 22 def fonts @fonts end |
#images ⇒ Object (readonly)
:nodoc:
22 23 24 |
# File 'lib/epdfdw.rb', line 22 def images @images end |
#in_page ⇒ Object (readonly)
Returns the value of attribute in_page.
23 24 25 |
# File 'lib/epdfdw.rb', line 23 def in_page @in_page end |
#pages ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/epdfdw.rb', line 20 def pages @pages end |
#resources ⇒ Object (readonly)
:nodoc:
21 22 23 |
# File 'lib/epdfdw.rb', line 21 def resources @resources end |
Instance Method Details
#arc(x, y, r, start_angle, end_angle, move_to0 = false) ⇒ Object
Draw an arc with origin x, y
and radius r
from start_angle
to end_angle
degrees. Direction is counterclockwise (anticlockwise), unless end_angle
< start_angle
. Angles are allowed to exceed 360 degrees.
By default, arc extends the current path to the point where the arc begins. If move_to0
is true (or there is no current path) a move is performed to where the arc begins.
This method returns immediately if start_angle == end_angle
.
328 329 330 |
# File 'lib/epdfdw.rb', line 328 def arc(x, y, r, start_angle, end_angle, move_to0=false) cur_page.arc(x, y, r, start_angle, end_angle, move_to0) end |
#arch(x, y, r1, r2, start_angle, end_angle, options = {}, &block) ⇒ Object
Draw an arch with origin x, y
from start_angle
to end_angle degrees. The result is a bounded area between radii r1
and r2
.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
If true and a block is given, the shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
By default, the bounding path is drawn from
(r1, start_angle)
to(r1, end_angle)
,(r2, end_angle)
,(r2, start_angle)
and back to(r1, start_angle)
. This order is reversed ifreverse => true
. This is useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
353 354 355 |
# File 'lib/epdfdw.rb', line 353 def arch(x, y, r1, r2, start_angle, end_angle, ={}, &block) cur_page.arch(x, y, r1, r2, start_angle, end_angle, , &block) end |
#auto_path ⇒ Object
Returns current status of auto_path. Defaults to true
. False while in a block given to path
method. When true
, paths are automatically stroked before a new, non-contiguous segment is appended or a closed shape is drawn.
390 391 392 |
# File 'lib/epdfdw.rb', line 390 def auto_path cur_page.auto_path end |
#bullet(name, options = {}, &block) ⇒ Object
Given a block, defines a named bullet. Otherwise the named Bullet struct is returned.
The following options
apply:
- :
units
-
The units that :
width
is expressed in. Defaults to the current units setting. - :
width
-
The width of the area reserved for the bullet.
If a block is given, the block should expect a writer
parameter to be used for printing or drawing the bullet. Within the block, all altered settings, other than the location, should be restored.
672 673 674 |
# File 'lib/epdfdw.rb', line 672 def bullet(name, ={}, &block) cur_page.bullet(name, , &block) end |
#canvas_height ⇒ Object
page_width
excluding left and right margins.
167 168 169 |
# File 'lib/epdfdw.rb', line 167 def canvas_height cur_page.canvas_height end |
#canvas_width ⇒ Object
page_height
excluding top and bottom margins.
162 163 164 |
# File 'lib/epdfdw.rb', line 162 def canvas_width cur_page.canvas_width end |
#circle(x, y, r, options = {}, &block) ⇒ Object
Draw a circle with center x, y
and radius r
. Direction is counterclockwise (anticlockwise), unless :reverse
option is specified.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
The shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
Draw circle clockwise. Useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
292 293 294 |
# File 'lib/epdfdw.rb', line 292 def circle(x, y, r, ={}, &block) cur_page.circle(x, y, r, , &block) end |
#clip(options = {}, &block) ⇒ Object
Use current path as a clipping boundary for anything drawn within the supplied block.
The following options
apply:
- :
stroke
-
If true, the current path is stroked with the current
line_color
. Defaults tofalse
. - :
fill
-
If true, the area bounded by the current path is filled with the current
fill_color
. Defaults tofalse
.
428 429 430 |
# File 'lib/epdfdw.rb', line 428 def clip(={}, &block) cur_page.clip(, &block) end |
#close ⇒ Object
Close any open pages, preparing the document for rendering to PDF.
63 64 65 66 67 |
# File 'lib/epdfdw.rb', line 63 def close open_page if @pages.empty? # empty document needs at least one page close_page if @in_page @pages.each { |page| page.close unless page.closed? } end |
#close_page ⇒ Object
Close the current open page. Raises Exception if no page is currently open.
99 100 101 102 103 104 |
# File 'lib/epdfdw.rb', line 99 def close_page raise Exception.new("Not in page") unless @in_page @cur_page.close @cur_page = nil @in_page = false end |
#cur_page ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/epdfdw.rb', line 122 def cur_page # :nodoc: @cur_page || open_page end |
#curve(x0, y0, x1, y1, x2, y2, x3, y3) ⇒ Object
Draw a cubic Bezier curve from (x0, y0)
to (x3, y3)
with control points <x1, y1>
and (x2, y2)
. If the first point does not coincide with the current position, any current path is stroked and a new path is begun. Otherwise, the curve is appended to the current path.
264 265 266 |
# File 'lib/epdfdw.rb', line 264 def curve(x0, y0, x1, y1, x2, y2, x3, y3) cur_page.curve(x0, y0, x1, y1, x2, y2, x3, y3) end |
#curve_points(points) ⇒ Object
Draw a series of cubic Bezier curves. After moving to the first point, a curve to the 4th point is appended to the current path with the 2nd and 3rd points acting as control points. A curve is appended to the current path for each additional group of 3 points, with the 1st and 2nd point in each group acting as control points.
points
-
array of
Location
structs
273 274 275 |
# File 'lib/epdfdw.rb', line 273 def curve_points(points) cur_page.curve_points(points) end |
#doc(options = {}) {|_self| ... } ⇒ Object
Open the document for writing and yield to the block given before calling close
.
70 71 72 73 74 |
# File 'lib/epdfdw.rb', line 70 def doc(={}, &block) open() yield(self) close end |
#ellipse(x, y, rx, ry, options = {}) ⇒ Object
Draw an ellipse with foci (x, y
) and (x, y
) and radius r
. Direction is counterclockwise (anticlockwise), unless :reverse
option is specified.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
The shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
Draw ellipse clockwise. Useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
311 312 313 |
# File 'lib/epdfdw.rb', line 311 def ellipse(x, y, rx, ry, ={}) cur_page.ellipse(x, y, rx, ry, ) end |
#fill ⇒ Object
Fill current path (begun by path
method) and resume auto_path
. The line_color
and fill_color
in effect before path
was begun are restored. Raises Exception if no current path exists.
407 408 409 |
# File 'lib/epdfdw.rb', line 407 def fill cur_page.fill end |
#fill_and_stroke ⇒ Object
Fill and stroke current path (begun by pat
method) and resume auto_path
. The line_color
and fill_color
in effect before path
was begun are restored. Raises Exception if no current path exists.
419 420 421 |
# File 'lib/epdfdw.rb', line 419 def fill_and_stroke cur_page.fill_and_stroke end |
#fill_color(color = nil) ⇒ Object
Set fill color, returning previous fill color. If no color is specified, returns current fill color.
color
-
Tuple (array) containing [red, green, blue] components of new color (where components range from 0..255) or integer encoded from rgb bytes where blue is in the least-significant byte.
Return values are always in integer form.
468 469 470 |
# File 'lib/epdfdw.rb', line 468 def fill_color(color=nil) cur_page.fill_color(color) end |
#font(name = nil, size = nil, options = {}) ⇒ Object
Set font, returning previous font. If no font is specified, returns current font.
name
-
Base name of a Type1 font with metrics file in fonts directory.
size
-
Size of font in points. See also
font_size
method.
The following options
apply:
- :
style
-
Bold, Italic, Oblique or a combination of weight and style such as BoldItalic or BoldOblique. See
font_style
method. - :
color
-
Font color as given to
font_color
method. Color is unchanged if not specified. - :
encoding
-
Currently-supported encodings include StandardEncoding, WinAnsiEncoding/CP1250, CP1250, CP1254, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-7, ISO-8859-9, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, MacTurkish or Macintosh. Defaults to WinAnsiEncoding.
- :
sub_type
-
Currently only Type1 fonts are supported. Defaults to Type1.
- :
fill
-
Fill text with current
font_color
. Defaults totrue
. - :
stroke
-
Stroke text with current
line_color
. Defaults tofalse
.
608 609 610 |
# File 'lib/epdfdw.rb', line 608 def font(name=nil, size=nil, ={}) cur_page.font(name, size, ) end |
#font_color(color = nil) ⇒ Object
Set font color, returning previous font color. If no color is specified, returns current font color.
color
-
Tuple (array) containing [red, green, blue] components of new color (where components range from 0..255) or integer encoded from rgb bytes where blue is in the least-significant byte.
Return values are always in integer form.
475 476 477 |
# File 'lib/epdfdw.rb', line 475 def font_color(color=nil) cur_page.font_color(color) end |
#font_encoding(encoding = nil) ⇒ Object
Set font encoding, returning previous font encoding. If no encoding is specified, returns current font encoding.
480 481 482 |
# File 'lib/epdfdw.rb', line 480 def font_encoding(encoding=nil) cur_page.font_encoding(encoding) end |
#font_size(size = nil) ⇒ Object
Set font size, returning previous font size. If no size is specified, returns current font size.
size
-
Size of font in points.
621 622 623 |
# File 'lib/epdfdw.rb', line 621 def font_size(size=nil) cur_page.font_size(size) end |
#font_style(style = nil) ⇒ Object
Set font style, returning previous font style. If no style is specified, returns current font style.
style
-
Bold (or other weight), Italic, Oblique or combination such as BoldItalic or BoldOblique.
Exact weights and combinations available depend on the font specification files in the (local) fonts directory.
615 616 617 |
# File 'lib/epdfdw.rb', line 615 def font_style(style=nil) cur_page.font_style(style) end |
#height(text = '', units = nil) ⇒ Object
Returns height of a line or array of lines, including external leading as determined by line_height
.
text
-
Line or array of lines to be measured. Height is determined only by current font and number of lines.
units
-
Units result should be expressed in. Defaults to current
units
.
547 548 549 |
# File 'lib/epdfdw.rb', line 547 def height(text='', units=nil) # may not include external leading? cur_page.height(text, units) end |
#indent(value = nil, absolute = false) ⇒ Object
Set horizontal indentation. If no value is specified, returns current indentation setting.
value
-
The new indentation.
absolute
-
If
true
, the new value is relative only to the left margin. Iffalse
, value is relative to previous indentation.
The indent setting is used by the puts
and new_line
methods.
199 200 201 |
# File 'lib/epdfdw.rb', line 199 def indent(value=nil, absolute=false) cur_page.indent(value, absolute) end |
#jpeg?(image) ⇒ Boolean
Returns true
if image is a buffer beginning with a JPEG signature.
626 627 628 |
# File 'lib/epdfdw.rb', line 626 def jpeg?(image) cur_page.jpeg?(image) end |
#jpeg_dimensions(image) ⇒ Object
Returns a tuple (array) of image dimensions of the form [width, height, components, bits_per_component]. Raises ArgumentError if image
is not a JPEG.
632 633 634 |
# File 'lib/epdfdw.rb', line 632 def jpeg_dimensions(image) cur_page.jpeg_dimensions(image) end |
#line(x, y, angle, length) ⇒ Object
Draw a line from point (x, y)
to a point length
units distant at angle
degrees.
244 245 246 |
# File 'lib/epdfdw.rb', line 244 def line(x, y, angle, length) cur_page.line(x, y, angle, length) end |
#line_cap_style(style = nil) ⇒ Object
Set the shape to be used at the ends of lines. If no style is specified, returns current style.
style
-
One of the symbols :butt_cap, :round_cap or :projecting_square_cap, or a string ‘butt_cap’, ‘round_cap’ or ‘projecting_square_cap’.
434 435 436 |
# File 'lib/epdfdw.rb', line 434 def line_cap_style(style=nil) cur_page.line_cap_style(style) end |
#line_color(color = nil) ⇒ Object
Set line color, returning previous line color. If no color is specified, returns current font color.
color
-
Tuple (array) containing [red, green, blue] components of new color (where components range from 0..255), string key into
named_colors
or integer encoded from rgb bytes where blue is in the least-significant byte.
Return values are always in string or integer form.
461 462 463 |
# File 'lib/epdfdw.rb', line 461 def line_color(color=nil) cur_page.line_color(color) end |
#line_dash_pattern(pattern = nil) ⇒ Object
Set the pattern of dashes and gaps used to draw lines. If no pattern is specified, returns current pattern.
pattern
-
A string of the form ‘[dash gap] phase’ or one of the symbols :
solid
, :dotted
or :dashed
.
When a symbol is specified, dash and gap lengths are multiplied by line_width
for proportion.
441 442 443 |
# File 'lib/epdfdw.rb', line 441 def line_dash_pattern(pattern=nil) cur_page.line_dash_pattern(pattern) end |
#line_height(height = nil) ⇒ Object
Set line height as used by methods like paragraph
that display multiple lines of text. If no value is specified, returns current line_height
.
height
-
Ratio of
font_size
to effective line height.
216 217 218 |
# File 'lib/epdfdw.rb', line 216 def line_height(height=nil) cur_page.line_height(height) end |
#line_to(x, y) ⇒ Object
Draw a line from the current location to point (x, y)
. If auto_path
is off, a new segment is appended to the current path.
239 240 241 |
# File 'lib/epdfdw.rb', line 239 def line_to(x, y) cur_page.line_to(x, y) end |
#line_width(value = nil, units = nil) ⇒ Object
Set line width used when stroking paths. If no width is specified, returns current line_width
.
value
-
If
value
is a number, the newline_width
setting. Ifvalue
is a symbol (such as :pt, :cm or :in), the units to return the currentline_width
in. Ifvalue
is a string, it may include the units as a suffix, e.g. “5.5in” for 5.5 inches. units
-
Units value is expressed in. Defaults to current units setting.
448 449 450 |
# File 'lib/epdfdw.rb', line 448 def line_width(value=nil, units=nil) cur_page.line_width(value, units) end |
#load_image(image_file_name, stream = nil) ⇒ Object
:nodoc:
636 637 638 |
# File 'lib/epdfdw.rb', line 636 def load_image(image_file_name, stream=nil) # :nodoc: cur_page.load_image(image_file_name, stream) end |
#margin_bottom ⇒ Object
Returns bottom margin as set by margins
method.
152 153 154 |
# File 'lib/epdfdw.rb', line 152 def margin_bottom cur_page.margin_bottom end |
#margin_left ⇒ Object
Returns left margin as set by margins
method.
157 158 159 |
# File 'lib/epdfdw.rb', line 157 def margin_left cur_page.margin_left end |
#margin_right ⇒ Object
Returns right margin as set by margins
method.
147 148 149 |
# File 'lib/epdfdw.rb', line 147 def margin_right cur_page.margin_right end |
#margin_top ⇒ Object
Returns top margin as set by margins
method.
142 143 144 |
# File 'lib/epdfdw.rb', line 142 def margin_top cur_page.margin_top end |
#margins(*margins) ⇒ Object
Set top, right, bottom and left margins. If 1, 2 or 4 values are not specified, returns current margins as a tuple (array) of values in the form [top, right, bottom, left].
margins
-
When 4 values are given, [top, right, bottom, left]. When 2 values are given, [top and bottom, right and left]. When 1 value is specified, it is used for all 4 settings.
137 138 139 |
# File 'lib/epdfdw.rb', line 137 def margins(*margins) cur_page.margins(*margins) end |
#move_by(dx, dy) ⇒ Object
Move the pen to a new location relative to the current location.
dx
-
Horizontal distance to move pen. Positive values move right. Negative values move left.
dy
-
Vertical distance to move pen. Positive values move down. Negative values move up.
233 234 235 |
# File 'lib/epdfdw.rb', line 233 def move_by(dx, dy) cur_page.move_by(dx, dy) end |
#move_to(x, y) ⇒ Object
Move pen to point (x, y)
.
221 222 223 |
# File 'lib/epdfdw.rb', line 221 def move_to(x, y) cur_page.move_to(x, y) end |
#named_colors ⇒ Object
Returns hash of named colors consisting of (name, color) pairs. Initial value comes from EideticPDF::PdfK::NAMED_COLORS, but may be augmented or replaced.
454 455 456 |
# File 'lib/epdfdw.rb', line 454 def named_colors @named_colors ||= PdfK::NAMED_COLORS.dup end |
#new_line(count = 1) ⇒ Object
Move pen down one or more lines and back to current indent.
count
-
Number of lines to move down.
517 518 519 |
# File 'lib/epdfdw.rb', line 517 def new_line(count=1) cur_page.new_line(count) end |
#new_page(options = {}) ⇒ Object
Close the current page and begin a new page with the specified options.
options
-
See
open_page
method.
117 118 119 120 |
# File 'lib/epdfdw.rb', line 117 def new_page(={}) close_page open_page() end |
#next_seq ⇒ Object
:nodoc:
16 17 18 |
# File 'lib/epdfdw.rb', line 16 def next_seq # :nodoc: @next_seq += 1 end |
#open(options = {}) ⇒ Object
Open the document for writing.
The following document options apply:
- :
pages_up
-
A tuple (array) of the form [
pages_across
,pages_down
] specifying the layout of virtual pages. Defaults to [1, 1] (no virtual pages). - :
pages_up_layout
-
When :
across
, virtual pages proceed from left to right before top to bottom. When :down
, virtual pages proceed from top to bottom before left to right.
In addition, any of the options for open_page
may be supplied and will apply to each page, unless explicitly overridden.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/epdfdw.rb', line 45 def open(={}) raise Exception.new("Already in document") if @in_doc @in_doc = true @options = @pages = [] @next_seq = 0 @file = PdfObjects::PdfFile.new pages = PdfObjects::PdfPages.new(next_seq, 0) outlines = PdfObjects::PdfOutlines.new(next_seq, 0) @catalog = PdfObjects::PdfCatalog.new(next_seq, 0, :use_none, pages, outlines) @file.body << pages << outlines << @catalog @file.trailer.root = @catalog define_resources @pages_across, @pages_down = [:pages_up] || [1, 1] @pages_up = @pages_across * @pages_down end |
#open_page(options = {}) ⇒ Object
Open a page for writing. Raises Exception if a page is already open.
The following page options apply:
- :
compress
-
Compress page streams using zlib deflate.
- :
units
-
A symbol from EideticPDF::UNIT_CONVERSION hash, specifying ratio of units to points. Defaults to :
pt
. Other choices are :in
for inches and :cm
for centimeters. Custom units may be added. - :
v_text_align
-
Initial vertical text alignment for page. See
v_text_align
method. - :
font
-
Initial font for page. Defaults to
{ :name => 'Helvetica', :size => 12 }
. - :
fill_color
-
Initial fill color. Defaults to 0 (black). See
fill_color
method. - :
line_color
-
Initial line color. Defaults to 0 (black). See
line_color
method. - :
line_height
-
Initial line height. Defaults to 1.7. See
line_height
method. - :
line_width
-
Initial line width. Defaults to 1.0. See
line_width
method. - :
margins
-
Page margins. Defaults to 0. See
margins
method. - :
unscaled
-
If true, virtual pages are not scaled down. Defaults to
false
.
89 90 91 92 93 94 95 96 |
# File 'lib/epdfdw.rb', line 89 def open_page(={}) raise Exception.new("Already in page") if @in_page .update(:_page => pdf_page(@pages.size), :sub_page => sub_page(@pages.size)) @cur_page = PageWriter.new(self, @options.merge()) @pages << @cur_page @in_page = true return @cur_page end |
#page(options = {}) {|cur_page| ... } ⇒ Object
Open a page for writing and yield to the block given before calling close_page
.
options
is passed through to open_page
.
109 110 111 112 113 |
# File 'lib/epdfdw.rb', line 109 def page(={}, &block) cur_page = open_page() yield(cur_page) close_page end |
#page_height ⇒ Object
Returns page height in current units.
209 210 211 |
# File 'lib/epdfdw.rb', line 209 def page_height cur_page.page_height end |
#page_width ⇒ Object
Returns page width in current units.
204 205 206 |
# File 'lib/epdfdw.rb', line 204 def page_width cur_page.page_width end |
#paragraph(text, options = {}) ⇒ Object
Wrap text
and render with the following options
.
- :
width
-
Maximum width to wrap text within. Defaults to the canvas width minus the current horizontal position.
- :
height
-
Maximum height allowed. Any text not rendered will be returned by the method call. Defaults to the canvas height minus the current vertical position.
- :
bullet
-
Render paragraph as a bullet, using the named bullet as defined using the
bullet
method. The bullet width is subtracted from the :width
specified.
555 556 557 |
# File 'lib/epdfdw.rb', line 555 def paragraph(text, ={}) cur_page.paragraph(text, ) end |
#paragraph_xy(x, y, text, options = {}) ⇒ Object
Move to (x, y)
and render paragraph.
560 561 562 |
# File 'lib/epdfdw.rb', line 560 def paragraph_xy(x, y, text, ={}) cur_page.paragraph_xy(x, y, text, ) end |
#path(options = {}, &block) ⇒ Object
Turn off auto_path. If a block is given, yields to it before filling and/or stroking anything drawn within it according to the options
supplied. The path may be non-contiguous. Shapes may be hollow when inner paths are drawn in the opposite direction as outer paths.
The following options apply:
- :
stroke
-
If true or a color, the path will be stroked with the current or specified
line_color
, respectively. Defaults tofalse
. - :
fill
-
If true or a color, the area bounded by the path will be filled with the current or specified
fill_color
, respectively. Defaults tofalse
.
401 402 403 |
# File 'lib/epdfdw.rb', line 401 def path(={}, &block) cur_page.path(, &block) end |
#pen_pos(x = nil, y = nil) ⇒ Object
Move pen to point (x, y)
like move_to
, returning previous location. If x is not specified, returns current location.
226 227 228 |
# File 'lib/epdfdw.rb', line 226 def pen_pos(x=nil, y=nil) cur_page.pen_pos(x, y) end |
#pie(x, y, r, start_angle, end_angle, options = {}) ⇒ Object
Draw a pie-shaped wedge with origin x, y
and radius r
from start_angle
to end_angle
degrees.
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
If true and a block is given, the shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
By default, the bounding path is drawn from
(x, y)
to(r, start_angle)
through(r, end_angle)
and back to(x, y)
. This order is reversed if:reverse => true
. This is useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
339 340 341 |
# File 'lib/epdfdw.rb', line 339 def pie(x, y, r, start_angle, end_angle, ={}) cur_page.pie(x, y, r, start_angle, end_angle, ) end |
#points_for_arc(x, y, r, start_angle, end_angle) ⇒ Object
Returns array of Location
structs for arc, suitable for feeding to curve_points
method. See arc
method.
316 317 318 |
# File 'lib/epdfdw.rb', line 316 def points_for_arc(x, y, r, start_angle, end_angle) cur_page.points_for_arc(x, y, r, start_angle, end_angle) end |
#points_for_circle(x, y, r) ⇒ Object
Returns array of Location
structs for circle, suitable for feeding to curve_points
method. See circle
method.
278 279 280 |
# File 'lib/epdfdw.rb', line 278 def points_for_circle(x, y, r) cur_page.points_for_circle(x, y, r) end |
#points_for_ellipse(x, y, rx, ry) ⇒ Object
Returns array of Location
structs for ellipse, suitable for feeding to curve_points
method. See ellipse
method.
297 298 299 |
# File 'lib/epdfdw.rb', line 297 def points_for_ellipse(x, y, rx, ry) cur_page.points_for_ellipse(x, y, rx, ry) end |
#points_for_polygon(x, y, r, sides, options = {}) ⇒ Object
Returns array of Location
structs representing the vertices of a polygon. See polygon
method.
358 359 360 |
# File 'lib/epdfdw.rb', line 358 def points_for_polygon(x, y, r, sides, ={}) cur_page.points_for_polygon(x, y, r, sides, ) end |
#polygon(x, y, r, sides, options = {}) ⇒ Object
Draw a polygon with origin (x, y)
, radius r
and the specified number of sides
.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
If true and a block is given, the shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
Draw polygon clockwise. This is useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
371 372 373 |
# File 'lib/epdfdw.rb', line 371 def polygon(x, y, r, sides, ={}) cur_page.polygon(x, y, r, sides, ) end |
#print(text, options = {}, &block) ⇒ Object
Print text, starting from the current position.
The following options apply:
- :
align
-
When :
left
, left edge of text is aligned to current position. When :center
, text is centered at current position. When :right
, right edge of text is aligned to current position. When any alignment is specified, the pen is restored to its original location. - :
angle
-
Print text at the specified
angle
in degrees. Defaults to 0. - :
scale
-
Horizontal scaling of text, specified as ratio to normal width. Defaults to 1.0. Cannot be combined with :
clip
. - :
underline
-
Override
underline
setting for this piece of text. - :
clip
-
If true and a block is given, the edges of the text act as a clipping boundary for anything drawn within the supplied block. Cannot be combined with :
scale
. - :
fill
-
(Only applicable with :
clip
) Fill text and add to path for clipping. - :
stroke
-
(Only applicable with :
clip
) Stroke text with currentline_color
and add to path for clipping.
These current settings also apply: font
, font_color
, line_color
(when outlines are stroked) and vertical text alignment (v_text_align
).
496 497 498 |
# File 'lib/epdfdw.rb', line 496 def print(text, ={}, &block) cur_page.print(text, , &block) end |
#print_image(data, x = nil, y = nil, width = nil, height = nil) ⇒ Object
Display graphic (currently only JPEG is supported) from disk (or network, if open-uri library is loaded) and display at the specified location.
data
-
Buffer containing image.
x
-
Left edge of image is placed at this offset. Defaults to
pen_pos.x
. y
-
Top edge of image is placed at this offset. Defaults to
pen_pos.y
. width
-
Width to make image. Defaults to natural image width or a width proportionate to
height
ifheight
is specified. height
-
Height to make image. Defaults to natural image height or a height proportionate to
width
ifwidth
is specified.
656 657 658 |
# File 'lib/epdfdw.rb', line 656 def print_image(data, x=nil, y=nil, width=nil, height=nil) cur_page.print_image(data, x, y, width, height) end |
#print_image_file(image_file_name, x = nil, y = nil, width = nil, height = nil) ⇒ Object
Load graphic file (currently only JPEG is supported) from disk (or network, if open-uri library is loaded) and display at the specified location.
image_file_name
-
Path or URL to image.
x
-
Left edge of image is placed at this offset. Defaults to
pen_pos.x
. y
-
Top edge of image is placed at this offset. Defaults to
pen_pos.y
. width
-
Width to make image. Defaults to natural image width or a width proportionate to
height
ifheight
is specified. height
-
Height to make image. Defaults to natural image height or a height proportionate to
width
ifwidth
is specified.
646 647 648 |
# File 'lib/epdfdw.rb', line 646 def print_image_file(image_file_name, x=nil, y=nil, width=nil, height=nil) cur_page.print_image_file(image_file_name, x, y, width, height) end |
#print_link(s, uri) ⇒ Object
:nodoc:
660 661 662 |
# File 'lib/epdfdw.rb', line 660 def print_link(s, uri) # :nodoc: cur_page.print_link(s, uri) end |
#print_xy(x, y, text, options = {}, &block) ⇒ Object
Move to (x, y)
and print text. See print
method.
501 502 503 |
# File 'lib/epdfdw.rb', line 501 def print_xy(x, y, text, ={}, &block) cur_page.print_xy(x, y, text, , &block) end |
#puts(text = '', options = {}, &block) ⇒ Object
Print one or more lines of text before moving to the next line, as specified by indent
.
506 507 508 |
# File 'lib/epdfdw.rb', line 506 def puts(text='', ={}, &block) cur_page.puts(text, , &block) end |
#puts_xy(x, y, text, options = {}, &block) ⇒ Object
Move to (x, y)
and print one or more lines of text indented to x
. See puts
method.
511 512 513 |
# File 'lib/epdfdw.rb', line 511 def puts_xy(x, y, text, ={}, &block) cur_page.puts_xy(x, y, text, ={}, &block) end |
#rectangle(x, y, width, height, options = {}) ⇒ Object
Draw a rectangle with the specified width
and height
and its top, left corner at (x, y)
.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
If true and a block is given, the shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
Draw polygon clockwise. This is useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
257 258 259 |
# File 'lib/epdfdw.rb', line 257 def rectangle(x, y, width, height, ={}) cur_page.rectangle(x, y, width, height, ) end |
#rotate(angle, x, y, &block) ⇒ Object
Rotate anything drawn within the supplied block angle
degrees around origin (x, y)
.
677 678 679 |
# File 'lib/epdfdw.rb', line 677 def rotate(angle, x, y, &block) cur_page.rotate(angle, x, y, &block) end |
#scale(x, y, scale_x, scale_y, &block) ⇒ Object
681 682 683 |
# File 'lib/epdfdw.rb', line 681 def scale(x, y, scale_x, scale_y, &block) cur_page.scale(x, y, scale_x, scale_y, &block) end |
#star(x, y, r1, r2, points, options = {}) ⇒ Object
Draw a star with origin (x, y)
, outer radius r1
, inner radius r2
and the specified number of sides
.
The following options
apply:
- :
border
-
If true or a color, a border is drawn with the current or specified
line_color
, respectively. Defaults totrue
. - :
fill
-
If true or a color, the area is filled with the current or specified
fill_color
, respectively. Defaults tofalse
. - :
clip
-
If true and a block is given, the shape acts as a clipping boundary for anything drawn within the supplied block.
- :
reverse
-
Draw polygon clockwise. This is useful for drawing hollow shapes.
These current settings also apply: line_color
, line_width
, line_dash_pattern
and fill_color
.
384 385 386 |
# File 'lib/epdfdw.rb', line 384 def star(x, y, r1, r2, points, ={}) cur_page.star(x, y, r1, r2, points, ) end |
#stroke ⇒ Object
Stroke current path (begun by path
method) and resume auto_path
. The line_color
and fill_color
in effect before path
was begun are restored. Raises Exception if no current path exists.
413 414 415 |
# File 'lib/epdfdw.rb', line 413 def stroke cur_page.stroke end |
#tab(&block) ⇒ Object
Move right to next horizontal tab. If no more tab stops exist, then moves to first tab stop on the following line. If a block is given, the value returned is used instead as the vertical distance to move down.
179 180 181 |
# File 'lib/epdfdw.rb', line 179 def tab(&block) cur_page.tab(&block) end |
#tabs(tabs = nil) ⇒ Object
Set horizontal tabs using an array of numbers or a comma-delimited string. If no tabs are specified, returns current tabs. Use false to clear current tab stops.
173 174 175 |
# File 'lib/epdfdw.rb', line 173 def tabs(tabs=nil) cur_page.tabs(tabs) end |
#text_ascent(units = nil) ⇒ Object
Returns text ascent, based on the current font.
units
-
Units the value is returned in.
534 535 536 |
# File 'lib/epdfdw.rb', line 534 def text_ascent(units=nil) cur_page.text_ascent(units) end |
#text_height(units = nil) ⇒ Object
Returns text height, based on the current font, excluding external leading.
units
-
Units the value is returned in.
540 541 542 |
# File 'lib/epdfdw.rb', line 540 def text_height(units=nil) cur_page.text_height(units) end |
#to_s ⇒ Object
Render document to PDF and return as a binary string.
34 35 36 |
# File 'lib/epdfdw.rb', line 34 def to_s @file.to_s end |
#truetype_font_names ⇒ Object
:nodoc:
590 591 592 593 594 595 596 |
# File 'lib/epdfdw.rb', line 590 def truetype_font_names # :nodoc: if @options[:built_in_fonts] PdfTT::FONT_NAMES else raise Exception.new("Non-built-in TrueType fonts not supported yet.") end end |
#type1_font_names ⇒ Object
Returns an array of font names, including weight and style, from the (local) fonts directory.
582 583 584 585 586 587 588 |
# File 'lib/epdfdw.rb', line 582 def type1_font_names if @options[:built_in_fonts] PdfK::FONT_NAMES else AFM::font_names end end |
#underline(underline = nil) ⇒ Object
Set new underline status, returning previous status. If new status is not specified, returns current underline status.
577 578 579 |
# File 'lib/epdfdw.rb', line 577 def underline(underline=nil) cur_page.underline(underline) end |
#units(units = nil) ⇒ Object
Set units measurements are to be specified in. If no units are specified, returns current units setting. Valid units include :pt
(points), :in
(inches) and :cm
(centimeters) by default.
Custom units can be specified by updating the EideticPDF::UNIT_CONVERSION hash with a new symbol and conversion ratio.
130 131 132 |
# File 'lib/epdfdw.rb', line 130 def units(units=nil) cur_page.units(units) end |
#v_text_align(vta = nil) ⇒ Object
Set vertical text alignment. This is the part of the text that would coincide with a line if one were drawn at the same coordinates as the text.
- :
above
-
At the top of the text, plus an amount equal to the height of descenders.
- :
top
-
At the top of the text–text is rendered below the line.
- :
middle
-
Through the middle of the text, like a strikeout.
- :
base
-
At the base of the text–text is rendered above the line, except for descenders.
- :
below
-
Below the text–text is rendered above the line, including descenders.
Default is :top
.
572 573 574 |
# File 'lib/epdfdw.rb', line 572 def v_text_align(vta=nil) cur_page.v_text_align(vta) end |
#vtab(&block) ⇒ Object
Move down to next vertical tab. If no more tab stops exist and a block is given, moves up to the first vertical tab stop and right the value returned by the block.
191 192 193 |
# File 'lib/epdfdw.rb', line 191 def vtab(&block) cur_page.vtab(&block) end |
#vtabs(tabs = nil) ⇒ Object
Set vertical tabs using an array of numbers or a comma-delimited string. If no tabs are specified, returns current tabs. Use false to clear current tab stops.
185 186 187 |
# File 'lib/epdfdw.rb', line 185 def vtabs(tabs=nil) cur_page.vtabs(tabs) end |
#width(text) ⇒ Object
Returns width of a string as rendered using the current font.
522 523 524 |
# File 'lib/epdfdw.rb', line 522 def width(text) cur_page.width(text) end |
#wrap(text, length) ⇒ Object
Breaks text into tokens and reassembles into array of strings, each one not exceeding length
. Newlines are respected and all other white space is preserved.
528 529 530 |
# File 'lib/epdfdw.rb', line 528 def wrap(text, length) cur_page.wrap(text, length) end |