pdf-labels 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/LICENCE +38 -0
- data/Manifest.txt +141 -0
- data/README.txt +72 -0
- data/Rakefile +30 -0
- data/lib/alias.rb +8 -0
- data/lib/glabel_template.rb +36 -0
- data/lib/label.rb +52 -0
- data/lib/layout.rb +13 -0
- data/lib/length_node.rb +47 -0
- data/lib/markup.rb +25 -0
- data/lib/pdf_label_page.rb +171 -0
- data/lib/pdf_labels.rb +6 -0
- data/lib/template.rb +37 -0
- data/templates/avery-iso-templates.xml +222 -0
- data/templates/avery-other-templates.xml +21 -0
- data/templates/avery-us-templates.xml +599 -0
- data/templates/glabels-2.0.dtd +329 -0
- data/templates/misc-iso-templates.xml +434 -0
- data/templates/misc-other-templates.xml +21 -0
- data/templates/misc-us-templates.xml +183 -0
- data/templates/paper-sizes.xml +37 -0
- data/templates/zweckform-iso-templates.xml +197 -0
- data/test/test_pdf_label_page.rb +91 -0
- data/vendor/color.rb +87 -0
- data/vendor/color/cmyk.rb +182 -0
- data/vendor/color/css.rb +27 -0
- data/vendor/color/grayscale.rb +135 -0
- data/vendor/color/hsl.rb +130 -0
- data/vendor/color/palette.rb +15 -0
- data/vendor/color/palette/gimp.rb +107 -0
- data/vendor/color/palette/monocontrast.rb +180 -0
- data/vendor/color/rgb-colors.rb +189 -0
- data/vendor/color/rgb.rb +311 -0
- data/vendor/color/rgb/metallic.rb +28 -0
- data/vendor/color/yiq.rb +78 -0
- data/vendor/pdf/charts.rb +13 -0
- data/vendor/pdf/charts/stddev.rb +433 -0
- data/vendor/pdf/grid.rb +135 -0
- data/vendor/pdf/math.rb +108 -0
- data/vendor/pdf/pagenumbers.rb +288 -0
- data/vendor/pdf/quickref.rb +331 -0
- data/vendor/pdf/simpletable.rb +947 -0
- data/vendor/pdf/techbook.rb +901 -0
- data/vendor/pdf/writer.rb +2801 -0
- data/vendor/pdf/writer/arc4.rb +63 -0
- data/vendor/pdf/writer/fontmetrics.rb +202 -0
- data/vendor/pdf/writer/fonts/Courier-Bold.afm +342 -0
- data/vendor/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
- data/vendor/pdf/writer/fonts/Courier-Oblique.afm +342 -0
- data/vendor/pdf/writer/fonts/Courier.afm +342 -0
- data/vendor/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
- data/vendor/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/vendor/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
- data/vendor/pdf/writer/fonts/Helvetica.afm +3051 -0
- data/vendor/pdf/writer/fonts/Symbol.afm +213 -0
- data/vendor/pdf/writer/fonts/Times-Bold.afm +2588 -0
- data/vendor/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
- data/vendor/pdf/writer/fonts/Times-Italic.afm +2667 -0
- data/vendor/pdf/writer/fonts/Times-Roman.afm +2419 -0
- data/vendor/pdf/writer/fonts/ZapfDingbats.afm +225 -0
- data/vendor/pdf/writer/graphics.rb +813 -0
- data/vendor/pdf/writer/graphics/imageinfo.rb +365 -0
- data/vendor/pdf/writer/lang.rb +44 -0
- data/vendor/pdf/writer/lang/en.rb +104 -0
- data/vendor/pdf/writer/object.rb +23 -0
- data/vendor/pdf/writer/object/action.rb +40 -0
- data/vendor/pdf/writer/object/annotation.rb +42 -0
- data/vendor/pdf/writer/object/catalog.rb +39 -0
- data/vendor/pdf/writer/object/contents.rb +69 -0
- data/vendor/pdf/writer/object/destination.rb +40 -0
- data/vendor/pdf/writer/object/encryption.rb +53 -0
- data/vendor/pdf/writer/object/font.rb +68 -0
- data/vendor/pdf/writer/object/fontdescriptor.rb +34 -0
- data/vendor/pdf/writer/object/fontencoding.rb +40 -0
- data/vendor/pdf/writer/object/image.rb +308 -0
- data/vendor/pdf/writer/object/info.rb +79 -0
- data/vendor/pdf/writer/object/outline.rb +30 -0
- data/vendor/pdf/writer/object/outlines.rb +30 -0
- data/vendor/pdf/writer/object/page.rb +195 -0
- data/vendor/pdf/writer/object/pages.rb +115 -0
- data/vendor/pdf/writer/object/procset.rb +46 -0
- data/vendor/pdf/writer/object/viewerpreferences.rb +74 -0
- data/vendor/pdf/writer/ohash.rb +58 -0
- data/vendor/pdf/writer/oreader.rb +25 -0
- data/vendor/pdf/writer/state.rb +48 -0
- data/vendor/pdf/writer/strokestyle.rb +140 -0
- data/vendor/transaction/simple.rb +693 -0
- data/vendor/transaction/simple/group.rb +133 -0
- data/vendor/transaction/simple/threadsafe.rb +52 -0
- data/vendor/transaction/simple/threadsafe/group.rb +23 -0
- data/vendor/xml-mapping/ChangeLog +128 -0
- data/vendor/xml-mapping/LICENSE +56 -0
- data/vendor/xml-mapping/README +386 -0
- data/vendor/xml-mapping/README_XPATH +175 -0
- data/vendor/xml-mapping/Rakefile +214 -0
- data/vendor/xml-mapping/TODO.txt +32 -0
- data/vendor/xml-mapping/doc/xpath_impl_notes.txt +119 -0
- data/vendor/xml-mapping/examples/company.rb +34 -0
- data/vendor/xml-mapping/examples/company.xml +26 -0
- data/vendor/xml-mapping/examples/company_usage.intin.rb +19 -0
- data/vendor/xml-mapping/examples/company_usage.intout +39 -0
- data/vendor/xml-mapping/examples/order.rb +61 -0
- data/vendor/xml-mapping/examples/order.xml +54 -0
- data/vendor/xml-mapping/examples/order_signature_enhanced.rb +7 -0
- data/vendor/xml-mapping/examples/order_signature_enhanced.xml +9 -0
- data/vendor/xml-mapping/examples/order_signature_enhanced_usage.intin.rb +12 -0
- data/vendor/xml-mapping/examples/order_signature_enhanced_usage.intout +16 -0
- data/vendor/xml-mapping/examples/order_usage.intin.rb +73 -0
- data/vendor/xml-mapping/examples/order_usage.intout +147 -0
- data/vendor/xml-mapping/examples/time_augm.intin.rb +19 -0
- data/vendor/xml-mapping/examples/time_augm.intout +23 -0
- data/vendor/xml-mapping/examples/time_node.rb +27 -0
- data/vendor/xml-mapping/examples/xpath_create_new.intin.rb +85 -0
- data/vendor/xml-mapping/examples/xpath_create_new.intout +181 -0
- data/vendor/xml-mapping/examples/xpath_docvsroot.intin.rb +30 -0
- data/vendor/xml-mapping/examples/xpath_docvsroot.intout +34 -0
- data/vendor/xml-mapping/examples/xpath_ensure_created.intin.rb +62 -0
- data/vendor/xml-mapping/examples/xpath_ensure_created.intout +114 -0
- data/vendor/xml-mapping/examples/xpath_pathological.intin.rb +42 -0
- data/vendor/xml-mapping/examples/xpath_pathological.intout +56 -0
- data/vendor/xml-mapping/examples/xpath_usage.intin.rb +51 -0
- data/vendor/xml-mapping/examples/xpath_usage.intout +57 -0
- data/vendor/xml-mapping/install.rb +40 -0
- data/vendor/xml-mapping/lib/xml/mapping.rb +14 -0
- data/vendor/xml-mapping/lib/xml/mapping/base.rb +571 -0
- data/vendor/xml-mapping/lib/xml/mapping/standard_nodes.rb +343 -0
- data/vendor/xml-mapping/lib/xml/mapping/version.rb +8 -0
- data/vendor/xml-mapping/lib/xml/xxpath.rb +354 -0
- data/vendor/xml-mapping/test/all_tests.rb +6 -0
- data/vendor/xml-mapping/test/company.rb +56 -0
- data/vendor/xml-mapping/test/documents_folders.rb +33 -0
- data/vendor/xml-mapping/test/fixtures/bookmarks1.xml +24 -0
- data/vendor/xml-mapping/test/fixtures/company1.xml +85 -0
- data/vendor/xml-mapping/test/fixtures/documents_folders.xml +71 -0
- data/vendor/xml-mapping/test/fixtures/documents_folders2.xml +30 -0
- data/vendor/xml-mapping/test/multiple_mappings.rb +80 -0
- data/vendor/xml-mapping/test/tests_init.rb +2 -0
- data/vendor/xml-mapping/test/xml_mapping_adv_test.rb +84 -0
- data/vendor/xml-mapping/test/xml_mapping_test.rb +201 -0
- data/vendor/xml-mapping/test/xpath_test.rb +273 -0
- metadata +191 -0
@@ -0,0 +1,308 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: image.rb,v 1.3 2005/08/26 03:13:24 austin Exp $
|
10
|
+
#++
|
11
|
+
require 'pdf/writer/oreader'
|
12
|
+
|
13
|
+
# An image object. This will be an /XObject dictionary in the document. This
|
14
|
+
# includes description and data. The diectionary includes:
|
15
|
+
#
|
16
|
+
# Type:: (name, Optional) The type of PDF object that this
|
17
|
+
# dictionary describes; if present, must be /XObject for
|
18
|
+
# an image XObject.
|
19
|
+
# Subtype:: (name, Required) The type of XObject that this
|
20
|
+
# dictionary describes; must be /Image for an image
|
21
|
+
# /XObject.
|
22
|
+
# Width:: (integer, Required) The width of the image, in samples.
|
23
|
+
# Height:: (integer, Required) The height of the image, in samples.
|
24
|
+
# ColorSpace:: (name or array, Required for images, except those that
|
25
|
+
# use the /JPXDecode filter; not allowed for image
|
26
|
+
# masks) The color space in which image samples are
|
27
|
+
# specified; it can be any type of color space except
|
28
|
+
# /Pattern. If the image uses the JPXDecode filter, this
|
29
|
+
# entry is optional: * If /ColorSpace is present, any
|
30
|
+
# color space specifications in the JPEG2000 data are
|
31
|
+
# ignored. * If /ColorSpace is absent, the color space
|
32
|
+
# specifications in the JPEG2000 data are used. The
|
33
|
+
# /Decode array is also ignored unless /ImageMask is
|
34
|
+
# true.
|
35
|
+
# BitsPerComponent:: (integer, Required except for image masks and images
|
36
|
+
# that use the JPXDecode filter) The number of bits used
|
37
|
+
# to represent each color component. Only a single value
|
38
|
+
# may be specified; the number of bits is the same for
|
39
|
+
# all color components. Valid values are 1, 2, 4, 8, and
|
40
|
+
# (in PDF 1.5) 16. If /ImageMask is true, this entry is
|
41
|
+
# optional, and if specified, its value must be 1. If
|
42
|
+
# the image stream uses a filter, the value of
|
43
|
+
# BitsPerComponent must be consistent with the size of
|
44
|
+
# the data samples that the filter delivers. In
|
45
|
+
# particular, a CCITTFaxDecode or JBIG2Decode filter
|
46
|
+
# always delivers 1-bit samples, a RunLengthDecode or
|
47
|
+
# DCTDecode filter delivers 8-bit samples, and an
|
48
|
+
# LZWDecode or FlateDecode filter delivers samples of a
|
49
|
+
# specified size if a predictor function is used. If the
|
50
|
+
# image stream uses the JPXDecode filter, this entry is
|
51
|
+
# optional and ignored if present. The bit depth is
|
52
|
+
# determined in the process of decoding the JPEG2000
|
53
|
+
# image.
|
54
|
+
# Intent:: (name, Optional; PDF 1.1) The name of a color
|
55
|
+
# rendering intent to be used in rendering the image
|
56
|
+
# (see �Rendering Intents� on page 230). Default value:
|
57
|
+
# the current rendering intent in the graphics state.
|
58
|
+
# ImageMask:: (boolean, Optional) A flag indicating whether the
|
59
|
+
# image is to be treated as an image mask (see Section
|
60
|
+
# 4.8.5, �Masked Images�). If this flag is true, the
|
61
|
+
# value of /BitsPerComponent must be 1 and Mask and
|
62
|
+
# /ColorSpace should not be specified; unmasked areas
|
63
|
+
# are painted using the current nonstroking color.
|
64
|
+
# Default value: false.
|
65
|
+
# Mask:: (stream or array, Optional except for image masks; not
|
66
|
+
# allowed for image masks; PDF 1.3) An image XObject
|
67
|
+
# defining an image mask to be applied to this image
|
68
|
+
# (see �Explicit Masking� on page 321), or an array
|
69
|
+
# specifying a range of colors to be applied to it as a
|
70
|
+
# color key mask (see �Color Key Masking� on page 321).
|
71
|
+
# If ImageMask is true, this entry must not be present.
|
72
|
+
# (See implementation note 51 in Appendix H.)
|
73
|
+
# Decode:: (array, Optional) An array of numbers describing how
|
74
|
+
# to map image samples into the range of values
|
75
|
+
# appropriate for the image�s color space (see �Decode
|
76
|
+
# Arrays� on page 314). If ImageMask is true, the array
|
77
|
+
# must be either [0 1] or [1 0]; otherwise, its length
|
78
|
+
# must be twice the number of color components required
|
79
|
+
# by ColorSpace. If the image uses the JPXDecode filter
|
80
|
+
# and ImageMask is false, Decode is ignored. Default
|
81
|
+
# value: see �Decode Arrays� on page 314.
|
82
|
+
# Interpolate:: (boolean, Optional) A flag indicating whether image
|
83
|
+
# interpolation is to be performed (see �Image
|
84
|
+
# Interpolation� on page 316). Default value: false.
|
85
|
+
# Alternates:: (array, Optional; PDF 1.3) An array of alternate image
|
86
|
+
# dictionaries for this image (see �Alternate Images� on
|
87
|
+
# page 317). The order of elements within the array has
|
88
|
+
# no significance. This entry may not be present in an
|
89
|
+
# image XObject that is itself an alternate image.
|
90
|
+
# SMask:: (stream, Optional; PDF 1.4) A subsidiary image XObject
|
91
|
+
# defining a soft-mask image (see �Soft-Mask Images� on
|
92
|
+
# page 522) to be used as a source of mask shape or mask
|
93
|
+
# opacity values in the transparent imaging model. The
|
94
|
+
# alpha source parameter in the graphics state
|
95
|
+
# determines whether the mask values are interpreted as
|
96
|
+
# shape or opacity. If present, this entry overrides the
|
97
|
+
# current soft mask in the graphics state, as well as
|
98
|
+
# the image�s Mask entry, if any. (However, the other
|
99
|
+
# transparency related graphics state parameters�blend
|
100
|
+
# mode and alpha constant�remain in effect.) If SMask is
|
101
|
+
# absent, the image has no associated soft mask
|
102
|
+
# (although the current soft mask in the graphics state
|
103
|
+
# may still apply).
|
104
|
+
# SMaskInData:: (integer, Optional for images that use the JPXDecode
|
105
|
+
# filter, meaningless otherwise; PDF 1.5) A code
|
106
|
+
# specifying how soft-mask information (see �Soft-Mask
|
107
|
+
# Images� on page 522) encoded with image samples should
|
108
|
+
# be used: (0) If present, encoded soft-mask image
|
109
|
+
# information should be ignored. (1) The image�s data
|
110
|
+
# stream includes encoded soft-mask values. An
|
111
|
+
# application can create a soft-mask image from the
|
112
|
+
# information to be used as a source of mask shape or
|
113
|
+
# mask opacity in the transparency imaging model. (2)
|
114
|
+
# The image�s data stream includes color channels that
|
115
|
+
# have been preblended with a background; the image data
|
116
|
+
# also includes an opacity channel. An application can
|
117
|
+
# create a soft-mask image with a Matte entry from the
|
118
|
+
# opacity channel information to be used as a source of
|
119
|
+
# mask shape or mask opacity in the transparency model.
|
120
|
+
# * If this entry has a nonzero value, SMask should not
|
121
|
+
# be specified. See also Section 3.3.8, �JPXDecode
|
122
|
+
# Filter.� Default value: 0.
|
123
|
+
# Name:: (name, Required in PDF 1.0; optional otherwise) The
|
124
|
+
# name by which this image XObject is referenced in the
|
125
|
+
# XObject subdictionary of the current resource
|
126
|
+
# dictionary (see Section 3.7.2, �Resource
|
127
|
+
# Dictionaries�). Note: This entry is obsolescent and
|
128
|
+
# its use is no longer recommended. (See implementation
|
129
|
+
# note 52 in Appendix H.)
|
130
|
+
# StructParent:: (integer, Required if the image is a structural
|
131
|
+
# content item; PDF 1.3) The integer key of the image�s
|
132
|
+
# entry in the structural parent tree (see �Finding
|
133
|
+
# Structure Elements from Content Items� on page 797).
|
134
|
+
# ID:: (string, Optional; PDF 1.3; indirect reference
|
135
|
+
# preferred) The digital identifier of the image�s
|
136
|
+
# parent Web Capture content set (see Section 10.9.5,
|
137
|
+
# �Object Attributes Related to Web Capture�).
|
138
|
+
# OPI:: (dictionary, Optional; PDF 1.2) An OPI version
|
139
|
+
# dictionary for the image (see Section 10.10.6, �Open
|
140
|
+
# Prepress Interface (OPI)�). If ImageMask is true, this
|
141
|
+
# entry is ignored.
|
142
|
+
# Metadata:: (stream, Optional; PDF 1.4) A metadata stream
|
143
|
+
# containing metadata for the image (see Section 10.2.2,
|
144
|
+
# �Metadata Streams�).
|
145
|
+
# OC:: (dictionary, Optional; PDF 1.5) An optional content
|
146
|
+
# group or optional content membership dictionary (see
|
147
|
+
# Section 4.10, �Optional Content�), specifying the
|
148
|
+
# optional content properties for this image XObject.
|
149
|
+
# Before the image is processed, its visibility is
|
150
|
+
# determined based on this entry. If it is determined to
|
151
|
+
# be invisible, the entire image is skipped, as if there
|
152
|
+
# were no Do operator to invoke it.
|
153
|
+
class PDF::Writer::External::Image < PDF::Writer::External
|
154
|
+
attr_reader :label
|
155
|
+
attr_reader :image_info
|
156
|
+
|
157
|
+
def initialize(parent, data, image, label)
|
158
|
+
super(parent)
|
159
|
+
|
160
|
+
@data = data
|
161
|
+
|
162
|
+
@image_info = image
|
163
|
+
|
164
|
+
@info = {
|
165
|
+
'Type' => '/XObject',
|
166
|
+
'Subtype' => '/Image',
|
167
|
+
'Width' => image.width,
|
168
|
+
'Height' => image.height
|
169
|
+
}
|
170
|
+
|
171
|
+
case image.format
|
172
|
+
when "JPEG"
|
173
|
+
case image.channels
|
174
|
+
when 1
|
175
|
+
@info['ColorSpace'] = '/DeviceGray'
|
176
|
+
when 4
|
177
|
+
@info['ColorSpace'] = '/DeviceCMYK'
|
178
|
+
# This should fix problems with CMYK JPEG colours inverted in
|
179
|
+
# Adobe Acrobat. Enable only if appropriate.
|
180
|
+
# @info['Decode'] = '[1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0]'
|
181
|
+
else
|
182
|
+
@info['ColorSpace'] = '/DeviceRGB'
|
183
|
+
end
|
184
|
+
@info['Filter'] = '/DCTDecode'
|
185
|
+
@info['BitsPerComponent'] = 8
|
186
|
+
when "PNG"
|
187
|
+
if image.info[:compression_method] != 0
|
188
|
+
raise TypeError, PDF::Writer::Lang[:png_unsupp_compres]
|
189
|
+
end
|
190
|
+
|
191
|
+
if image.info[:filter_method] != 0
|
192
|
+
raise TypeError, PDF::Writer::Lang[:png_unsupp_filter]
|
193
|
+
end
|
194
|
+
|
195
|
+
data = data.dup
|
196
|
+
data.extend(PDF::Writer::OffsetReader)
|
197
|
+
|
198
|
+
data.read_o(8) # Skip the default header
|
199
|
+
|
200
|
+
ok = true
|
201
|
+
length = data.size
|
202
|
+
palette = ""
|
203
|
+
idat = ""
|
204
|
+
|
205
|
+
while ok
|
206
|
+
chunk_size = data.read_o(4).unpack("N")[0]
|
207
|
+
section = data.read_o(4)
|
208
|
+
case section
|
209
|
+
when 'PLTE'
|
210
|
+
palette << data.read_o(chunk_size)
|
211
|
+
when 'IDAT'
|
212
|
+
idat << data.read_o(chunk_size)
|
213
|
+
when 'tRNS'
|
214
|
+
# This chunk can only occur once and it must occur after the
|
215
|
+
# PLTE chunk and before the IDAT chunk
|
216
|
+
trans = {}
|
217
|
+
case image.info[:color_type]
|
218
|
+
when 3
|
219
|
+
# Indexed colour, RGB. Each byte in this chunk is an alpha for
|
220
|
+
# the palette index in the PLTE ("palette") chunk up until the
|
221
|
+
# last non-opaque entry. Set up an array, stretching over all
|
222
|
+
# palette entries which will be 0 (opaque) or 1 (transparent).
|
223
|
+
trans[:type] = 'indexed'
|
224
|
+
trans[:data] = data.read_o(chunk_size).unpack("C*")
|
225
|
+
when 0
|
226
|
+
# Greyscale. Corresponding to entries in the PLTE chunk.
|
227
|
+
# Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1
|
228
|
+
trans[:grayscale] = data.read_o(2).unpack("n")
|
229
|
+
trans[:type] = 'indexed'
|
230
|
+
# trans[:data] = data.read_o.unpack("C")
|
231
|
+
when 2
|
232
|
+
# True colour with proper alpha channel.
|
233
|
+
trans[:rgb] = data.read_o(6).unpack("nnn")
|
234
|
+
end
|
235
|
+
else
|
236
|
+
data.offset += chunk_size
|
237
|
+
end
|
238
|
+
|
239
|
+
ok = (section != "IEND")
|
240
|
+
|
241
|
+
data.read_o(4) # Skip the CRC
|
242
|
+
end
|
243
|
+
|
244
|
+
if image.bits > 8
|
245
|
+
raise TypeError, PDF::Writer::Lang[:png_8bit_colour]
|
246
|
+
end
|
247
|
+
if image.info[:interlace_method] != 0
|
248
|
+
raise TypeError, PDF::Writer::Lang[:png_interlace]
|
249
|
+
end
|
250
|
+
|
251
|
+
ncolor = 1
|
252
|
+
colour = 'DeviceRGB'
|
253
|
+
case image.info[:color_type]
|
254
|
+
when 3
|
255
|
+
nil
|
256
|
+
when 2
|
257
|
+
ncolor = 3
|
258
|
+
when 0
|
259
|
+
colour = 'DeviceGray'
|
260
|
+
else
|
261
|
+
raise TypeError, PDF::Writer::Lang[:png_alpha_trans]
|
262
|
+
end
|
263
|
+
|
264
|
+
@info['Filter'] = '[/FlateDecode]'
|
265
|
+
@info['DecodeParms'] = "[<</Predictor 15 /Colors #{ncolor} /Columns #{image.width}>>]"
|
266
|
+
@info['BitsPerComponent'] = image.bits.to_s
|
267
|
+
|
268
|
+
unless palette.empty?
|
269
|
+
@info['ColorSpace'] = " [ /Indexed /DeviceRGB #{(palette.size / 3) - 1} "
|
270
|
+
contents = PDF::Writer::Object::Contents.new(parent,
|
271
|
+
self)
|
272
|
+
contents.data = palette
|
273
|
+
@info['ColorSpace'] << "#{contents.oid} 0 R ]"
|
274
|
+
|
275
|
+
if trans
|
276
|
+
case trans[:type]
|
277
|
+
when 'indexed'
|
278
|
+
@info['Mask'] = " [ #{trans[:data].join(' ')} ] "
|
279
|
+
end
|
280
|
+
end
|
281
|
+
else
|
282
|
+
@info['ColorSpace'] = "/#{colour}"
|
283
|
+
end
|
284
|
+
|
285
|
+
@data = idat
|
286
|
+
end
|
287
|
+
|
288
|
+
@label = label
|
289
|
+
|
290
|
+
# assign it a place in the named resource dictionary as an external
|
291
|
+
# object, according to the label passed in with it.
|
292
|
+
@parent.pages << self
|
293
|
+
# also make sure that we have the right procset object for it.
|
294
|
+
@parent.procset << 'ImageC'
|
295
|
+
end
|
296
|
+
|
297
|
+
def to_s
|
298
|
+
tmp = @data.dup
|
299
|
+
res = "\n#{@oid} 0 obj\n<<"
|
300
|
+
@info.each { |k, v| res << "\n/#{k} #{v}"}
|
301
|
+
if (@parent.encrypted?)
|
302
|
+
@parent.arc4.prepare(self)
|
303
|
+
tmp = @parent.arc4.encrypt(tmp)
|
304
|
+
end
|
305
|
+
res << "\n/Length #{tmp.size} >>\nstream\n#{tmp}\nendstream\nendobj\n"
|
306
|
+
res
|
307
|
+
end
|
308
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: info.rb,v 1.5 2005/10/12 14:41:41 austin Exp $
|
10
|
+
#++
|
11
|
+
|
12
|
+
require 'set'
|
13
|
+
|
14
|
+
# Define the document information -- metadata.
|
15
|
+
class PDF::Writer::Object::Info < PDF::Writer::Object
|
16
|
+
@types = Set.new
|
17
|
+
@types << "CreationDate"
|
18
|
+
@types << "Creator"
|
19
|
+
@types << "Title"
|
20
|
+
@types << "Author"
|
21
|
+
@types << "Subject"
|
22
|
+
@types << "Keywords"
|
23
|
+
@types << "ModDate"
|
24
|
+
@types << "Trapped"
|
25
|
+
@types << "Producer"
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_reader :types
|
29
|
+
|
30
|
+
def add_type(type)
|
31
|
+
@types << type.to_s
|
32
|
+
attr_accessor type.to_s.downcase.to_sym
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(parent)
|
37
|
+
super(parent)
|
38
|
+
|
39
|
+
@parent.instance_variable_set('@info', self)
|
40
|
+
|
41
|
+
@creationdate = Time.now
|
42
|
+
@creator = File.basename($0)
|
43
|
+
@producer = "PDF::Writer for Ruby"
|
44
|
+
@title = nil
|
45
|
+
@author = nil
|
46
|
+
@subject = nil
|
47
|
+
@keywords = nil
|
48
|
+
@moddate = nil
|
49
|
+
@trapped = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
@types.each do |type|
|
53
|
+
attr_accessor type.to_s.downcase.to_sym
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
@parent.arc4.prepare(self) if @parent.encrypted?
|
58
|
+
res = "\n#{@oid} 0 obj\n<<\n"
|
59
|
+
self.class.types.each do |type|
|
60
|
+
val = __send__(type.to_s.downcase.to_sym)
|
61
|
+
next if val.nil?
|
62
|
+
|
63
|
+
res << "/#{type} ("
|
64
|
+
if val.kind_of?(Time)
|
65
|
+
s = "D:%04d%02d%02d%02d%02d"
|
66
|
+
val = val.utc
|
67
|
+
val = s % [ val.year, val.month, val.day, val.hour, val.min ]
|
68
|
+
end
|
69
|
+
|
70
|
+
if @parent.encrypted?
|
71
|
+
res << PDF::Writer.escape(@parent.arc4.encrypt(val))
|
72
|
+
else
|
73
|
+
res << PDF::Writer.escape(val)
|
74
|
+
end
|
75
|
+
res << ")\n"
|
76
|
+
end
|
77
|
+
res << ">>\nendobj"
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: outline.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
10
|
+
#++
|
11
|
+
# Define the outlines in the doc, empty for now
|
12
|
+
class PDF::Writer::Object::Outline < PDF::Writer::Object
|
13
|
+
def initialize(parent, label, title = label)
|
14
|
+
super(parent)
|
15
|
+
|
16
|
+
@action = PDF::Writer::Action.new(parent, label, :ilink)
|
17
|
+
@title = title
|
18
|
+
|
19
|
+
parent.outlines.list << self
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
pos = @parent.outlines.list.index(self)
|
24
|
+
res = "\n#{@oid} 0 obj\n<< /Title (#{@title})"
|
25
|
+
res << " /Prev #{@parent.outlines.list[pos - 1].oid} 0 R" if pos.nonzero?
|
26
|
+
res << " /Next #{@parent.outlines.list[pos + 1].oid} 0 R" if @oid != parent.outlines.list[-1].oid
|
27
|
+
res << " /A #{@action.oid} 0 R>>\nendobj"
|
28
|
+
res
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: outlines.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
10
|
+
#++
|
11
|
+
# Define the outlines in the doc, empty for now
|
12
|
+
class PDF::Writer::Object::Outlines < PDF::Writer::Object
|
13
|
+
def initialize(parent)
|
14
|
+
super(parent)
|
15
|
+
|
16
|
+
@list = []
|
17
|
+
@parent.catalog.outlines = self
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :list
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
if @list.empty?
|
24
|
+
"\n#{@oid} 0 obj\n<< /Type /Outlines >>\nendobj"
|
25
|
+
else
|
26
|
+
"\n#{@oid} 0 obj\n<< /Type /Outlines /First #{@list[0].oid} 0 R /Last
|
27
|
+
#{@list[-1].oid} 0 R>>\nendobj"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|