Class: DynamicPDFApi::Font
- Inherits:
-
Object
- Object
- DynamicPDFApi::Font
- Defined in:
- lib/ruby_client/Font.rb
Overview
Represents font.
Constant Summary collapse
- @@times_roman =
nil- @@times_bold =
nil- @@times_italic =
nil- @@times_bold_italic =
nil- @@helvetica =
nil- @@helvetica_bold =
nil- @@helvetica_oblique =
nil- @@helvetica_boldOblique =
nil- @@courier =
nil- @@courier_bold =
nil- @@courier_oblique =
nil- @@courier_boldOblique =
nil- @@symbol =
nil- @@zapf_dingbats =
nil
Instance Attribute Summary collapse
-
#_name ⇒ Object
Returns the value of attribute _name.
-
#_resource ⇒ Object
Returns the value of attribute _resource.
-
#embed ⇒ Object
Gets or sets a boolean indicating whether to embed the font.
-
#resource_name ⇒ Object
Gets or sets a name for the font resource.
-
#subset ⇒ Object
Gets or sets a boolean indicating whether to subset embed the font.
Class Method Summary collapse
-
.courier ⇒ Object
Gets the Courier core font with Latin 1 encoding.
-
.courier_bold ⇒ Object
Gets the Courier Bold core font with Latin 1 encoding.
-
.courier_bold_oblique ⇒ Object
Gets the Courier Bold Oblique core font with Latin 1 encoding.
-
.courier_oblique ⇒ Object
Gets the Courier Oblique core font with Latin 1 encoding.
- .create_font(font_resource = nil, resource_name = nil) ⇒ Object
-
.from_file(file_path, resource_name = nil) ⇒ Object
Initializes a new instance of the Font class using the file path of the font and resource name.
- .from_stream(_stream, _resource_name = nil) ⇒ Object
- .from_system(font_name, resource_name = nil) ⇒ Object
- .get_google_font_text(name, weight, italic) ⇒ Object
-
.global(font_name) ⇒ Object
Gets the font from the global storage.
-
.google(font_name, bold = nil, italic = false) ⇒ Object
Gets the font from the google.
-
.helvetica ⇒ Object
Gets the Helvetica core font with Latin 1 encoding.
-
.helvetica_bold ⇒ Object
Gets the Helvetica Bold core font with Latin 1 encoding.
-
.helvetica_bold_oblique ⇒ Object
Gets the Helvetica Bold Oblique core font with Latin 1 encoding.
-
.helvetica_oblique ⇒ Object
Gets the Helvetica Oblique core font with Latin 1 encoding.
- .load_fonts ⇒ Object
- .read_font_name_table(reader) ⇒ Object
-
.symbol ⇒ Object
Gets the Symbol core font.
-
.times_bold ⇒ Object
Gets the Times Bold core font with Latin 1 encoding.
-
.times_bold_italic ⇒ Object
Gets the Times Bold Italic core font with Latin 1 encoding.
-
.times_italic ⇒ Object
Gets the Times Italic core font with Latin 1 encoding.
-
.times_roman ⇒ Object
Gets the Times Roman core font with Latin 1 encoding.
-
.zapf_dingbats ⇒ Object
Gets the Zapf Dingbats core font.
Instance Method Summary collapse
-
#initialize(cloud_resource_name = nil) ⇒ Font
constructor
Initializes a new instance of the Font class using the font name that is present in the cloud resource manager.
- #to_json(_options = {}) ⇒ Object
Constructor Details
#initialize(cloud_resource_name = nil) ⇒ Font
Initializes a new instance of the Font class using the font name that is present in the cloud resource manager.
27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_client/Font.rb', line 27 def initialize(cloud_resource_name = nil) @data = {} @_resource = nil @embed = nil @subset = nil @resource_name = cloud_resource_name @_name = SecureRandom.uuid end |
Instance Attribute Details
#_name ⇒ Object
Returns the value of attribute _name.
46 47 48 |
# File 'lib/ruby_client/Font.rb', line 46 def _name @_name end |
#_resource ⇒ Object
Returns the value of attribute _resource.
46 47 48 |
# File 'lib/ruby_client/Font.rb', line 46 def _resource @_resource end |
#embed ⇒ Object
Gets or sets a boolean indicating whether to embed the font.
51 52 53 |
# File 'lib/ruby_client/Font.rb', line 51 def @embed end |
#resource_name ⇒ Object
Gets or sets a name for the font resource.
61 62 63 |
# File 'lib/ruby_client/Font.rb', line 61 def resource_name @resource_name end |
#subset ⇒ Object
Gets or sets a boolean indicating whether to subset embed the font.
56 57 58 |
# File 'lib/ruby_client/Font.rb', line 56 def subset @subset end |
Class Method Details
.courier ⇒ Object
Gets the Courier core font with Latin 1 encoding.
146 147 148 149 150 151 |
# File 'lib/ruby_client/Font.rb', line 146 def self.courier @@courier = Font.new if @@courier.nil? @@courier._name = "courier" @@courier end |
.courier_bold ⇒ Object
Gets the Courier Bold core font with Latin 1 encoding.
156 157 158 159 160 161 |
# File 'lib/ruby_client/Font.rb', line 156 def self.courier_bold @@courier_bold = Font.new if @@courier_bold.nil? @@courier_bold._name = "courierBold" @@courier_bold end |
.courier_bold_oblique ⇒ Object
Gets the Courier Bold Oblique core font with Latin 1 encoding.
176 177 178 179 180 181 |
# File 'lib/ruby_client/Font.rb', line 176 def self.courier_bold_oblique @@courier_boldOblique = Font.new if @@courier_boldOblique.nil? @@courier_boldOblique._name = "courierBoldOblique" @@courier_boldOblique end |
.courier_oblique ⇒ Object
Gets the Courier Oblique core font with Latin 1 encoding.
166 167 168 169 170 171 |
# File 'lib/ruby_client/Font.rb', line 166 def self.courier_oblique @@courier_oblique = Font.new if @@courier_oblique.nil? @@courier_oblique._name = "courierOblique" @@courier_oblique end |
.create_font(font_resource = nil, resource_name = nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/ruby_client/Font.rb', line 37 def self.create_font(font_resource = nil, resource_name = nil) font = Font.new font._resource = font_resource font.resource_name = resource_name font._name = SecureRandom.uuid font end |
.from_file(file_path, resource_name = nil) ⇒ Object
Initializes a new instance of the Font class using the file path of the font and resource name.
209 210 211 212 |
# File 'lib/ruby_client/Font.rb', line 209 def self.from_file(file_path, resource_name = nil) resource = Resource.new(file_path, resource_name) Font.create_font(resource, resource.resource_name) end |
.from_stream(_stream, _resource_name = nil) ⇒ Object
214 215 216 217 |
# File 'lib/ruby_client/Font.rb', line 214 def self.from_stream(_stream, _resource_name = nil) resource = Resource.new(stream, resource_name) Font.create_font(resource, resource.resource_name) end |
.from_system(font_name, resource_name = nil) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/ruby_client/Font.rb', line 261 def self.from_system(font_name, resource_name = nil) return nil if font_name.nil? || font_name.strip.empty? font_name = font_name.gsub(/[- ]/, "") # Removing the space and - from font_name self.load_fonts if @load_required @font_details.each do |detail| if detail._name.casecmp(font_name).zero? font_resource = FontResource.new(detail.file_path, resource_name) return Font.create_font(font_resource, font_resource.resource_name) end end nil end |
.get_google_font_text(name, weight, italic) ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/ruby_client/Font.rb', line 219 def self.get_google_font_text(name, weight, italic) if italic == true name + ":" + weight.to_s + "italic" else name + ":" + weight.to_s end end |
.global(font_name) ⇒ Object
Gets the font from the global storage.
255 256 257 258 259 |
# File 'lib/ruby_client/Font.rb', line 255 def self.global(font_name) font = Font.new() font._name = font_name font end |
.google(font_name, bold = nil, italic = false) ⇒ Object
Gets the font from the google.
235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/ruby_client/Font.rb', line 235 def self.google(font_name, bold = nil, italic = false) font = Font.new() if bold == true font._name = Font.get_google_font_text(font_name, 700, italic) elsif (bold.is_a?(Integer) == true) font._name = Font.get_google_font_text(font_name, bold, italic); elsif bold == false font._name = Font.get_google_font_text(font_name, 400, italic); else font._name = font_name; end font end |
.helvetica ⇒ Object
Gets the Helvetica core font with Latin 1 encoding.
106 107 108 109 110 111 |
# File 'lib/ruby_client/Font.rb', line 106 def self.helvetica @@helvetica = Font.new if @@helvetica.nil? @@helvetica._name = "helvetica" @@helvetica end |
.helvetica_bold ⇒ Object
Gets the Helvetica Bold core font with Latin 1 encoding.
116 117 118 119 120 121 |
# File 'lib/ruby_client/Font.rb', line 116 def self.helvetica_bold @@helvetica_bold = Font.new if @@helvetica_bold.nil? @@helvetica_bold._name = "helveticaBold" @@helvetica_bold end |
.helvetica_bold_oblique ⇒ Object
Gets the Helvetica Bold Oblique core font with Latin 1 encoding.
136 137 138 139 140 141 |
# File 'lib/ruby_client/Font.rb', line 136 def self.helvetica_bold_oblique @@helvetica_boldOblique = Font.new if @@helvetica_boldOblique.nil? @@helvetica_boldOblique._name = "helveticaBoldOblique" @@helvetica_boldOblique end |
.helvetica_oblique ⇒ Object
Gets the Helvetica Oblique core font with Latin 1 encoding.
126 127 128 129 130 131 |
# File 'lib/ruby_client/Font.rb', line 126 def self.helvetica_oblique @@helvetica_oblique = Font.new if @@helvetica_oblique.nil? @@helvetica_oblique._name = "helveticaOblique" @@helvetica_oblique end |
.load_fonts ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/ruby_client/Font.rb', line 278 def self.load_fonts return unless @load_required loaded_any = false @lock.synchronize do if @path_to_fonts_resource_directory && !@path_to_fonts_resource_directory.empty? dir_Info = File.join(@path_to_fonts_resource_directory.gsub("\\", "/"), "*") Dir.glob(dir_Info).each do |file_path| next unless file_path.downcase.end_with?(".ttf", ".otf") File.open(file_path, "rb") do |reader| name_table = self.read_font_name_table(reader) if name_table && name_table._name && !name_table._name.empty? @font_details << FontInformation.new(name_table._name, file_path) end end end end @load_required = false end end |
.read_font_name_table(reader) ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/ruby_client/Font.rb', line 302 def self.read_font_name_table(reader) name_table = nil begin reader.seek(4, IO::SEEK_SET) table_count = (reader.readbyte << 8) | reader.readbyte if table_count > 0 reader.seek(12, IO::SEEK_SET) table_directory = reader.read(table_count * 16).b (0...table_directory.size).step(16) do |i| tag_bytes = table_directory[i, 4] tag = tag_bytes.unpack1("V") if tag == 1701667182 # "name" name_table = FullNameTable.new(reader, table_directory, i) break end end end rescue => e puts "Error in read_font_name_table: #{e.}" end name_table end |
.symbol ⇒ Object
Gets the Symbol core font.
186 187 188 189 190 191 |
# File 'lib/ruby_client/Font.rb', line 186 def self.symbol @@symbol = Font.new if @@symbol.nil? @@symbol._name = "symbol" @@symbol end |
.times_bold ⇒ Object
Gets the Times Bold core font with Latin 1 encoding.
76 77 78 79 80 81 |
# File 'lib/ruby_client/Font.rb', line 76 def self.times_bold @@times_bold = Font.new if @@times_bold.nil? @@times_bold._name = "timesBold" @@times_bold end |
.times_bold_italic ⇒ Object
Gets the Times Bold Italic core font with Latin 1 encoding.
96 97 98 99 100 101 |
# File 'lib/ruby_client/Font.rb', line 96 def self.times_bold_italic @@times_bold_italic = Font.new if @@times_bold_italic.nil? @@times_bold_italic._name = "timesBoldItalic" @@times_bold_italic end |
.times_italic ⇒ Object
Gets the Times Italic core font with Latin 1 encoding.
86 87 88 89 90 91 |
# File 'lib/ruby_client/Font.rb', line 86 def self.times_italic @@times_italic = Font.new if @@times_italic.nil? @@times_italic._name = "timesItalic" @@times_italic end |
Instance Method Details
#to_json(_options = {}) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/ruby_client/Font.rb', line 325 def to_json( = {}) json_array = {} json_array["name"] = @_name unless @_name.nil? json_array["embed"] = @embed unless @embed.nil? json_array["subset"] = @subset unless @subset.nil? json_array["resourceName"] = @resource_name unless @resource_name.nil? JSON.pretty_generate(json_array) end |