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

Add decorationStrokeWidth. #1776

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions examples/textDecorations.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ ct.push({
{ text: 'Using colors', decoration: 'underline', decorationStyle: 'wavy', decorationColor: 'green' }
]
});
ct.push(' ');
ct.push({
columns: [
{ text: 'Stroke width 3', decoration: 'underline', decorationColor: 'blue', decorationStrokeWidth: 3, decorationStyle: 'dashed' },
{ text: 'Stroke width 5', decoration: 'underline', decorationColor: 'red', decorationStrokeWidth: 5, decorationStyle: 'dotted' },
{ text: 'Stroke width 2', decoration: 'underline', decorationColor: 'purple', decorationStrokeWidth: 2, decorationStyle: 'wavy' },
{ text: 'Stroke width 2', decoration: 'underline', decorationColor: 'black', decorationStrokeWidth: 2, decorationStyle: 'double' },
{ text: 'Stroke width 2', decoration: 'lineThrough', decorationColor: 'grey', decorationStrokeWidth: 2 }
]
});



Expand Down
1 change: 1 addition & 0 deletions src/StyleContextStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class StyleContextStack {
'decoration',
'decorationStyle',
'decorationColor',
'decorationStrokeWidth',
'background',
'lineHeight',
'characterSpacing',
Expand Down
12 changes: 9 additions & 3 deletions src/TextDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const groupDecorations = line => {
}
let color = inline.decorationColor || inline.color || 'black';
let style = inline.decorationStyle || 'solid';
let strokeWidth = typeof inline.decorationStrokeWidth === 'number'
? inline.decorationStrokeWidth
: null;
for (let ii = 0, ll = decoration.length; ii < ll; ii++) {
let decorationItem = decoration[ii];
if (!currentGroup || decorationItem !== currentGroup.decoration ||
Expand All @@ -25,6 +28,7 @@ const groupDecorations = line => {
decoration: decorationItem,
decorationColor: color,
decorationStyle: style,
decorationStrokeWidth: strokeWidth,
inlines: [inline]
};
groups.push(currentGroup);
Expand Down Expand Up @@ -91,7 +95,9 @@ class TextDecorator {
let height = biggerInline.height;
let descent = height - ascent;

let lw = 0.5 + Math.floor(Math.max(biggerInline.fontSize - 8, 0) / 2) * 0.12;
let lw = typeof group.decorationStrokeWidth === 'number'
? group.decorationStrokeWidth
: 0.5 + Math.floor(Math.max(biggerInline.fontSize - 8, 0) / 2) * 0.12;

switch (group.decoration) {
case 'underline':
Expand All @@ -109,7 +115,7 @@ class TextDecorator {
this.pdfDocument.save();

if (group.decorationStyle === 'double') {
let gap = Math.max(0.5, lw * 2);
let gap = Math.max(1.75, lw * .85 );
this.pdfDocument.fillColor(group.decorationColor)
.rect(x + firstInline.x, y - lw / 2, totalWidth, lw / 2).fill()
.rect(x + firstInline.x, y + gap - lw / 2, totalWidth, lw / 2).fill();
Expand All @@ -136,7 +142,7 @@ class TextDecorator {
let nbWaves = Math.ceil(totalWidth / (sh * 2)) + 1;
let rwx = x + firstInline.x - 1;
this.pdfDocument.rect(x + firstInline.x, y - sv, totalWidth, y + sv).clip();
this.pdfDocument.lineWidth(0.24);
this.pdfDocument.lineWidth(lw);
this.pdfDocument.moveTo(rwx, y);
for (let i = 0; i < nbWaves; i++) {
this.pdfDocument.bezierCurveTo(rwx + sh, y - sv, rwx + sh * 2, y - sv, rwx + sh * 3, y)
Expand Down
1 change: 1 addition & 0 deletions src/TextInlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TextInlines {
item.decoration = StyleContextStack.getStyleProperty(item, styleContextStack, 'decoration', null);
item.decorationColor = StyleContextStack.getStyleProperty(item, styleContextStack, 'decorationColor', null);
item.decorationStyle = StyleContextStack.getStyleProperty(item, styleContextStack, 'decorationStyle', null);
item.decorationStrokeWidth = StyleContextStack.getStyleProperty(item, styleContextStack, 'decorationStrokeWidth', null);
item.background = StyleContextStack.getStyleProperty(item, styleContextStack, 'background', null);
item.link = StyleContextStack.getStyleProperty(item, styleContextStack, 'link', null);
item.linkToPage = StyleContextStack.getStyleProperty(item, styleContextStack, 'linkToPage', null);
Expand Down