Skip to content

Commit 8604bdd

Browse files
committed
Fix Text word break
1 parent 888d866 commit 8604bdd

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

example/index.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,54 @@ <h3>This component render a printing template. It can be used as the core visual
135135
});
136136
}
137137

138+
function loadTemplate3() {
139+
loadTemplate({
140+
fields: [
141+
{
142+
useMacros: false,
143+
value: "This is a simple test for word break into two lines",
144+
color: 0,
145+
colorFill: -1,
146+
fontFamily: "Verdana",
147+
fontSize: "12pt",
148+
fontStyle: "Normal",
149+
align: "TopLeft",
150+
scaleFont: false,
151+
autoSize: false,
152+
wordBreak: true,
153+
maxLength: 0,
154+
width: 150,
155+
height: 55,
156+
x: 57,
157+
y: 29,
158+
zIndex: 0,
159+
rotation: 0,
160+
border: {
161+
width: 1,
162+
color: 0
163+
},
164+
type: "label"
165+
},
166+
{
167+
useMacros: false,
168+
color: 16777215,
169+
width: 256,
170+
height: 256,
171+
x: 186,
172+
y: 256,
173+
zIndex: 0,
174+
rotation: 0,
175+
border: {
176+
width: 1,
177+
color: 0
178+
},
179+
type: "rectangle"
180+
}
181+
],
182+
background: {}
183+
});
184+
}
185+
138186
loadTemplate();
139187
</script>
140188
</div>
@@ -143,6 +191,7 @@ <h3>This component render a printing template. It can be used as the core visual
143191
<p><button onclick="loadTemplate()">Empty card</button></p>
144192
<p><button onclick="loadTemplate1()">Template 1: Red card with Label and QR Code</button></p>
145193
<p><button onclick="loadTemplate2()">Template 2: Blue card with Shapes</button></p>
194+
<p><button onclick="loadTemplate3()">Template 3: Out of range single Shape</button></p>
146195
</div>
147196
</div>
148197

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@leosac/cardrendering",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"description": "Card Rendering engine for CR-80 cards and more",
55
"main": "dist/cardrendering.node.js",
66
"browser": "dist/cardrendering.js",

src/lib/fieldFactory.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ function createTextField(options, scale = 1)
4141
text.style = style;
4242
text.resolution = scale;
4343
if (options.wordBreak) {
44-
text.wordWrap = true;
45-
text.wordWrapWidth = options.width;
44+
text.style.wordWrap = true;
45+
text.style.wordWrapWidth = options.width;
46+
text.style.breakWords = true;
4647
}
4748
if (options.scaleFont) {
4849
let scale;
@@ -60,7 +61,7 @@ function createTextField(options, scale = 1)
6061
}
6162
}
6263
if (!options.autoSize) {
63-
while (text.width > options.width && text.text.length > 0) {
64+
while ((text.width > options.width || (options.wordBreak && text.height > options.height)) && text.text.length > 0) {
6465
text.text = text.text.substring(0, text.text.length - 1);
6566
}
6667
}

0 commit comments

Comments
 (0)