Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding options to manually set text rendering mode and stroke width. … #853

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions lib/mixins/text.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ module.exports =
align = options.align or 'left'
wordSpacing = options.wordSpacing or 0
characterSpacing = options.characterSpacing or 0
characterStrokeWidth = options.characterStrokeWidth or 0
mode = options.mode or 0
textBuildMode = options.textBuildMode or 0

# text alignments
if options.width
Expand Down Expand Up @@ -254,8 +257,6 @@ module.exports =
@stroke()
@restore()

@save()

# oblique (angle in degrees or boolean)
if options.oblique
if typeof options.oblique is 'number'
Expand All @@ -266,26 +267,26 @@ module.exports =
@transform 1, 0, skew, 1, -skew * dy, 0
@transform 1, 0, 0, 1, -x, -y

# flip coordinate system
@transform 1, 0, 0, -1, 0, @page.height
y = @page.height - y - dy

# add current font to page if necessary
@page.fonts[@_font.id] ?= @_font.ref()

# begin the text object
@addContent "BT"
@addContent "BT" if not textBuildMode

# text position
@addContent "1 0 0 1 #{number(x)} #{number(y)} Tm"
@addContent "1 0 0 -1 #{number(x)} #{number(y)} Tm"

# font and font size
@addContent "/#{@_font.id} #{number(@_fontSize)} Tf"

# rendering mode
mode = if options.fill and options.stroke then 2 else if options.stroke then 1 else 0
if not mode
mode = if options.fill and options.stroke then 2 else if options.stroke then 1 else 0
@addContent "#{mode} Tr" if mode

# character stroke width if applicable
@addContent "#{number(characterStrokeWidth)} w" if characterStrokeWidth

# Character spacing
@addContent "#{number(characterSpacing)} Tc" if characterSpacing

Expand Down Expand Up @@ -344,14 +345,14 @@ module.exports =
flush i

# Move the text position and flush just the current character
@addContent "1 0 0 1 #{number(x + pos.xOffset * scale)} #{number(y + pos.yOffset * scale)} Tm"
@addContent "1 0 0 -1 #{number(x + pos.xOffset * scale)} #{number(y + pos.yOffset * scale)} Tm"
flush i + 1

hadOffset = yes
else
# If the last character had an offset, reset the text position
if hadOffset
@addContent "1 0 0 1 #{number(x)} #{number(y)} Tm"
@addContent "1 0 0 -1 #{number(x)} #{number(y)} Tm"
hadOffset = no

# Group segments that don't have any advance adjustments
Expand All @@ -364,7 +365,4 @@ module.exports =
flush i

# end the text object
@addContent "ET"

# restore flipped coordinate system
@restore()
@addContent "ET" if not textBuildMode