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

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

#write_font(workbook, writer, font) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 278

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, 1000].min, 100].max
  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