mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
parent
55147c4412
commit
d35f7cc962
@ -1,25 +1,25 @@
|
||||
PDFFont = require '../font'
|
||||
|
||||
module.exports =
|
||||
module.exports =
|
||||
initFonts: ->
|
||||
# Lookup table for embedded fonts
|
||||
@_fontFamilies = {}
|
||||
@_fontCount = 0
|
||||
|
||||
|
||||
# Font state
|
||||
@_fontSize = 12
|
||||
@_font = null
|
||||
|
||||
|
||||
@_registeredFonts = {}
|
||||
|
||||
|
||||
# Set the default font
|
||||
@font 'Helvetica'
|
||||
|
||||
|
||||
font: (src, family, size) ->
|
||||
if typeof family is 'number'
|
||||
size = family
|
||||
family = null
|
||||
|
||||
|
||||
# check registered fonts if src is a string
|
||||
if typeof src is 'string' and @_registeredFonts[src]
|
||||
cacheKey = src
|
||||
@ -27,40 +27,42 @@ module.exports =
|
||||
else
|
||||
cacheKey = family or src
|
||||
cacheKey = null unless typeof cacheKey is 'string'
|
||||
|
||||
@fontSize size if size?
|
||||
|
||||
|
||||
@fontSize size if size?
|
||||
|
||||
# fast path: check if the font is already in the PDF
|
||||
if font = @_fontFamilies[cacheKey]
|
||||
@_font = font
|
||||
return this
|
||||
|
||||
|
||||
# load the font
|
||||
id = 'F' + (++@_fontCount)
|
||||
@_font = PDFFont.open(this, src, family, id)
|
||||
|
||||
|
||||
# check for existing font familes with the same name already in the PDF
|
||||
# useful if the font was passed as a buffer
|
||||
if font = @_fontFamilies[@_font.name]
|
||||
@_font = font
|
||||
return this
|
||||
|
||||
|
||||
# save the font for reuse later
|
||||
if cacheKey
|
||||
@_fontFamilies[cacheKey] = @_font
|
||||
|
||||
@_fontFamilies[@_font.name] = @_font
|
||||
|
||||
if @_font.name
|
||||
@_fontFamilies[@_font.name] = @_font
|
||||
|
||||
return this
|
||||
|
||||
|
||||
fontSize: (@_fontSize) ->
|
||||
return this
|
||||
|
||||
|
||||
currentLineHeight: (includeGap = false) ->
|
||||
@_font.lineHeight @_fontSize, includeGap
|
||||
|
||||
|
||||
registerFont: (name, src, family) ->
|
||||
@_registeredFonts[name] =
|
||||
@_registeredFonts[name] =
|
||||
src: src
|
||||
family: family
|
||||
|
||||
|
||||
return this
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user