Class: DynamicPDFApi::Font

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • cloud_resource_name (String) (defaults to: nil)

    The font name present in the cloud resource manager.



14
15
16
17
18
19
20
21
22
# File 'lib/ruby_client/Font.rb', line 14

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

#_nameObject

Returns the value of attribute _name.



33
34
35
# File 'lib/ruby_client/Font.rb', line 33

def _name
  @_name
end

#_resourceObject

Returns the value of attribute _resource.



33
34
35
# File 'lib/ruby_client/Font.rb', line 33

def _resource
  @_resource
end

#embedObject

Gets or sets a boolean indicating whether to embed the font.



38
39
40
# File 'lib/ruby_client/Font.rb', line 38

def embed
  @embed
end

#resource_nameObject

Gets or sets a name for the font resource.



48
49
50
# File 'lib/ruby_client/Font.rb', line 48

def resource_name
  @resource_name
end

#subsetObject

Gets or sets a boolean indicating whether to subset embed the font.



43
44
45
# File 'lib/ruby_client/Font.rb', line 43

def subset
  @subset
end

Class Method Details

.courierObject

Gets the Courier core font with Latin 1 encoding.



133
134
135
136
137
138
# File 'lib/ruby_client/Font.rb', line 133

def self.courier
  @@courier = Font.new if @@courier.nil?

  @@courier._name = "courier"
  @@courier
end

.courier_boldObject

Gets the Courier Bold core font with Latin 1 encoding.



143
144
145
146
147
148
# File 'lib/ruby_client/Font.rb', line 143

def self.courier_bold
  @@courier_bold = Font.new if @@courier_bold.nil?

  @@courier_bold._name = "courierBold"
  @@courier_bold
end

.courier_bold_obliqueObject

Gets the Courier Bold Oblique core font with Latin 1 encoding.



163
164
165
166
167
168
# File 'lib/ruby_client/Font.rb', line 163

def self.courier_bold_oblique
  @@courier_boldOblique = Font.new if @@courier_boldOblique.nil?

  @@courier_boldOblique._name = "courierBoldOblique"
  @@courier_boldOblique
end

.courier_obliqueObject

Gets the Courier Oblique core font with Latin 1 encoding.



153
154
155
156
157
158
# File 'lib/ruby_client/Font.rb', line 153

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



24
25
26
27
28
29
30
31
# File 'lib/ruby_client/Font.rb', line 24

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.

Parameters:

  • file_path (String)

    The file path of the font file.

  • resource_name (String) (defaults to: nil)

    The resource name for the font.



196
197
198
199
# File 'lib/ruby_client/Font.rb', line 196

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



201
202
203
204
# File 'lib/ruby_client/Font.rb', line 201

def self.from_stream(_stream, _resource_name = nil)
  resource = Resource.new(stream, resource_name)
  Font.create_font(resource, resource.resource_name)
end

.get_google_font_text(name, weight, italic) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/ruby_client/Font.rb', line 206

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.

Parameters:

  • fontName (string)

    The name of the font to get from the global storage..



242
243
244
245
246
# File 'lib/ruby_client/Font.rb', line 242

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.

Parameters:

  • fontName (string)

    The name of the google font.

  • bold (bold) (defaults to: nil)

    If true font weight will be taken as 700 otherwise 400.

  • italic (italic) (defaults to: false)

    The italic property of the font.



222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/ruby_client/Font.rb', line 222

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

.helveticaObject

Gets the Helvetica core font with Latin 1 encoding.



93
94
95
96
97
98
# File 'lib/ruby_client/Font.rb', line 93

def self.helvetica
  @@helvetica = Font.new if @@helvetica.nil?

  @@helvetica._name = "helvetica"
  @@helvetica
end

.helvetica_boldObject

Gets the Helvetica Bold core font with Latin 1 encoding.



103
104
105
106
107
108
# File 'lib/ruby_client/Font.rb', line 103

def self.helvetica_bold
  @@helvetica_bold = Font.new if @@helvetica_bold.nil?

  @@helvetica_bold._name = "helveticaBold"
  @@helvetica_bold
end

.helvetica_bold_obliqueObject

Gets the Helvetica Bold Oblique core font with Latin 1 encoding.



123
124
125
126
127
128
# File 'lib/ruby_client/Font.rb', line 123

def self.helvetica_bold_oblique
  @@helvetica_boldOblique = Font.new if @@helvetica_boldOblique.nil?

  @@helvetica_boldOblique._name = "helveticaBoldOblique"
  @@helvetica_boldOblique
end

.helvetica_obliqueObject

Gets the Helvetica Oblique core font with Latin 1 encoding.



113
114
115
116
117
118
# File 'lib/ruby_client/Font.rb', line 113

def self.helvetica_oblique
  @@helvetica_oblique = Font.new if @@helvetica_oblique.nil?

  @@helvetica_oblique._name = "helveticaOblique"
  @@helvetica_oblique
end

.symbolObject

Gets the Symbol core font.



173
174
175
176
177
178
# File 'lib/ruby_client/Font.rb', line 173

def self.symbol
  @@symbol = Font.new if @@symbol.nil?

  @@symbol._name = "symbol"
  @@symbol
end

.times_boldObject

Gets the Times Bold core font with Latin 1 encoding.



63
64
65
66
67
68
# File 'lib/ruby_client/Font.rb', line 63

def self.times_bold
  @@times_bold = Font.new if @@times_bold.nil?

  @@times_bold._name = "timesBold"
  @@times_bold
end

.times_bold_italicObject

Gets the Times Bold Italic core font with Latin 1 encoding.



83
84
85
86
87
88
# File 'lib/ruby_client/Font.rb', line 83

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_italicObject

Gets the Times Italic core font with Latin 1 encoding.



73
74
75
76
77
78
# File 'lib/ruby_client/Font.rb', line 73

def self.times_italic
  @@times_italic = Font.new if @@times_italic.nil?

  @@times_italic._name = "timesItalic"
  @@times_italic
end

.times_romanObject

Gets the Times Roman core font with Latin 1 encoding.



53
54
55
56
57
58
# File 'lib/ruby_client/Font.rb', line 53

def self.times_roman
  @@times_roman = Font.new if @@times_roman.nil?

  @@times_roman._name = "timesRoman"
  @@times_roman
end

.zapf_dingbatsObject

Gets the Zapf Dingbats core font.



183
184
185
186
187
188
# File 'lib/ruby_client/Font.rb', line 183

def self.zapf_dingbats
  @@zapf_dingbats = Font.new if @@zapf_dingbats.nil?

  @@zapf_dingbats._name = "zapfDingbats"
  @@zapf_dingbats
end

Instance Method Details

#to_json(_options = {}) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/ruby_client/Font.rb', line 248

def to_json(_options = {})
  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