Method: Spreadsheet::Excel::Writer::Workbook#write_font

Defined in:
lib/spreadsheet/excel/writer/workbook.rb

#write_font(workbook, writer, font) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 217

def write_font workbook, writer, font
  # TODO: Colors/Palette index
  size = font.size * TWIPS
  color = SEDOC_ROLOC[font.color] || SEDOC_ROLOC[:text]
  weight = FONT_WEIGHTS.fetch(font.weight, font.weight)
  weight = weight.clamp(100, 1000)
  esc = SEPYT_TNEMEPACSE.fetch(font.escapement, 0)
  underline = SEPYT_ENILREDNU.fetch(font.underline, 0)
  family = SEILIMAF_TNOF.fetch(font.family, 0)
  encoding = SGNIDOCNE_TNOF.fetch(font.encoding, 0)
  options = 0
  options |= 0x0001 if weight > 600
  options |= 0x0002 if font.italic?
  options |= 0x0004 if underline > 0
  options |= 0x0008 if font.strikeout?
  options |= 0x0010 if font.outline?
  options |= 0x0020 if font.shadow?
  data = [
    size,     # Height of the font (in twips = 1/20 of a point)
    options,  # Option flags:
    # Bit  Mask    Contents
    #   0  0x0001  1 = Characters are bold (redundant, see below)
    #   1  0x0002  1 = Characters are italic
    #   2  0x0004  1 = Characters are underlined (redundant)
    #   3  0x0008  1 = Characters are struck out
    #   4  0x0010  1 = Characters are outlined (djberger)
    #   5  0x0020  1 = Characters are shadowed (djberger)
    color,    # Palette index (➜ 6.70)
    weight,   # Font weight (100-1000). Standard values are
    #      0x0190 (400) for normal text and
    #      0x02bc (700) for bold text.
    esc,      # Escapement type: 0x0000 = None
    #                  0x0001 = Superscript
    #                  0x0002 = Subscript
    underline,  # Underline type:  0x00 = None
    #                  0x01 = Single
    #                  0x02 = Double
    #                  0x21 = Single accounting
    #                  0x22 = Double accounting
    family,   # Font family:     0x00 = None (unknown or don't care)
    #                  0x01 = Roman (variable width, serifed)
    #                  0x02 = Swiss (variable width, sans-serifed)
    #                  0x03 = Modern (fixed width,
    #                                 serifed or sans-serifed)
    #                  0x04 = Script (cursive)
    #                  0x05 = Decorative (specialised,
    #                                       e.g. Old English, Fraktur)
    encoding # Character set: 0x00 =   0 = ANSI Latin
    #                0x01 =   1 = System default
    #                0x02 =   2 = Symbol
    #                0x4d =  77 = Apple Roman
    #                0x80 = 128 = ANSI Japanese Shift-JIS
    #                0x81 = 129 = ANSI Korean (Hangul)
    #                0x82 = 130 = ANSI Korean (Johab)
    #                0x86 = 134 = ANSI Chinese Simplified GBK
    #                0x88 = 136 = ANSI Chinese Traditional BIG5
    #                0xa1 = 161 = ANSI Greek
    #                0xa2 = 162 = ANSI Turkish
    #                0xa3 = 163 = ANSI Vietnamese
    #                0xb1 = 177 = ANSI Hebrew
    #                0xb2 = 178 = ANSI Arabic
    #                0xba = 186 = ANSI Baltic
    #                0xcc = 204 = ANSI Cyrillic
    #                0xde = 222 = ANSI Thai
    #                0xee = 238 = ANSI Latin II (Central European)
    #                0xff = 255 = OEM Latin I
  ]
  name = unicode_string font.name # Font name: Unicode string,
  # 8-bit string length (➜ 3.4)
  write_op writer, opcode(:font), data.pack(binfmt(:font)), name
end