Class: PDFBeads::PageDataProvider::PageData
- Inherits:
-
Object
- Object
- PDFBeads::PageDataProvider::PageData
- Defined in:
- lib/pdfbeads/pdfpage.rb
Overview
Allows to collect data needed for building an individual page of a PDF document and gives access to those data.
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#bg_created ⇒ Object
readonly
Returns the value of attribute bg_created.
-
#bg_layer ⇒ Object
Returns the value of attribute bg_layer.
-
#fg_created ⇒ Object
readonly
Returns the value of attribute fg_created.
-
#fg_layer ⇒ Object
Returns the value of attribute fg_layer.
-
#height ⇒ Object
Returns the value of attribute height.
-
#hocr_path ⇒ Object
readonly
Returns the value of attribute hocr_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#s_type ⇒ Object
readonly
Returns the value of attribute s_type.
-
#stencils ⇒ Object
readonly
Returns the value of attribute stencils.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x_res ⇒ Object
Returns the value of attribute x_res.
-
#y_res ⇒ Object
Returns the value of attribute y_res.
Class Method Summary collapse
Instance Method Summary collapse
- #addSupplementaryFiles ⇒ Object
- #fillStencilArray ⇒ Object
-
#initialize(path, basename, args, exts, pref) ⇒ PageData
constructor
A new instance of PageData.
Constructor Details
#initialize(path, basename, args, exts, pref) ⇒ PageData
Returns a new instance of PageData.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pdfbeads/pdfpage.rb', line 43 def initialize( path,basename,args,exts,pref ) @name = path @basename = basename @s_type = 'b' @stencils = Array.new() @pageargs = args @exts = exts @pref = pref @bg_layer = @fg_layer = nil @bg_created = @fg_created = false end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def basename @basename end |
#bg_created ⇒ Object (readonly)
Returns the value of attribute bg_created.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def bg_created @bg_created end |
#bg_layer ⇒ Object
Returns the value of attribute bg_layer.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def bg_layer @bg_layer end |
#fg_created ⇒ Object (readonly)
Returns the value of attribute fg_created.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def fg_created @fg_created end |
#fg_layer ⇒ Object
Returns the value of attribute fg_layer.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def fg_layer @fg_layer end |
#height ⇒ Object
Returns the value of attribute height.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def height @height end |
#hocr_path ⇒ Object (readonly)
Returns the value of attribute hocr_path.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def hocr_path @hocr_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def name @name end |
#s_type ⇒ Object (readonly)
Returns the value of attribute s_type.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def s_type @s_type end |
#stencils ⇒ Object (readonly)
Returns the value of attribute stencils.
40 41 42 |
# File 'lib/pdfbeads/pdfpage.rb', line 40 def stencils @stencils end |
#width ⇒ Object
Returns the value of attribute width.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def width @width end |
#x_res ⇒ Object
Returns the value of attribute x_res.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def x_res @x_res end |
#y_res ⇒ Object
Returns the value of attribute y_res.
41 42 43 |
# File 'lib/pdfbeads/pdfpage.rb', line 41 def y_res @y_res end |
Class Method Details
.fixResolution(img) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/pdfbeads/pdfpage.rb', line 149 def self.fixResolution( img ) xres = img.x_resolution; yres = img.y_resolution if img.units == PixelsPerCentimeterResolution img.units = PixelsPerInchResolution xres = (xres * 2.54).round yres = (yres * 2.54).round end return [ xres, yres ] end |
Instance Method Details
#addSupplementaryFiles ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/pdfbeads/pdfpage.rb', line 105 def addSupplementaryFiles() force = @pageargs[:force_update] exts_pattern = @exts.join( '|' ) pref_pattern = @pref.join( '|' ) if @bg_layer.nil? bgpath = Dir.entries('.').detect do |f| /\A#{@basename}.(bg|sep).(#{pref_pattern})\Z/i.match(f) end bgpath = Dir.entries('.').detect do |f| /\A#{@basename}.(bg|sep).(#{exts_pattern})\Z/i.match(f) end if bgpath.nil? @bg_layer = bgpath unless bgpath.nil? # If updating auxiliary files is requested and the base image is # either bitonal or indexed with just a few colors (i. e. doesn't # contain any elements which should be placed to the background layer), # then the *.color.* image (if present) takes priority over any existing # *.bg.* and *.fg.* images. So we should regenerate them. if bgpath.nil? or ( force and not @s_type.eql? 'c' ) colorpath = Dir.entries('.').detect do |f| /\A#{@basename}.color.(#{exts_pattern})\Z/i.match(f) end unless colorpath.nil? fnames = Array.new() separateColor( colorpath ) end end end if @fg_layer.nil? and @stencils.length == 1 fgpath = Dir.entries('.').detect do |f| /\A#{@basename}.(fg).(#{exts_pattern})\Z/i.match(f) end @fg_layer = fgpath unless fgpath.nil? end if $has_nokogiri and not @pageargs[:pages_per_dict].nil? @hocr_path = Dir.entries('.').detect do |f| /\A#{@basename}.(HOCR|HTML?)/i.match(f) end end end |
#fillStencilArray ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pdfbeads/pdfpage.rb', line 55 def fillStencilArray() ret = 0 force = @pageargs[:force_update] fres = @pageargs[:st_resolution] treshold = @pageargs[:threshold] map = Hash[ :path => @name, :rgb => [0.0, 0.0, 0.0], :created => false ] insp = ImageInspector.new( @name ) return 0 if insp.width.nil? @width = insp.width; @height = insp.height unless fres > 0 @x_res = insp.x_dpi; @y_res = insp.y_dpi else @x_res = @y_res = fres end if insp.depth == 1 and insp.trans.nil? @stencils << map ret = 1 else img = ImageList.new( @name ) # ImageMagick incorrectly identifies indexed PNG images as DirectClass. # It also assigns a strange color value to fully opaque areas. So # we have to use an independent approach to recognize indexed images. unless insp.palette.nil? img.class_type = PseudoClass ret = processIndexed( img,@pageargs[:maxcolors],force ) end ret = processMixed( img,treshold,force,map ) if ret == 0 img.destroy! # Make sure there are no more RMagick objects GC.start end $stderr.puts( "Prepared data for processing #{@name}\n" ) if insp.nextImage $stderr.puts( "Warning: #{@name} contains multiple images, but only the first one") $stderr.puts( "\tis going to be used\n" ) end ret end |