Merge pull request #12106 from IQGeo/issue-12101
improve text width calculation
This commit is contained in:
@@ -104,6 +104,9 @@ export function drawTextOnPath(
|
||||
return result;
|
||||
}
|
||||
|
||||
// rendering across line segments
|
||||
text = text.replace(/\n/g, ' '); // ensure rendering in single-line as all calculations below don't handle multi-lines
|
||||
|
||||
for (let i = 0, ii = text.length; i < ii; ) {
|
||||
advance();
|
||||
let angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
|
||||
@@ -362,7 +362,9 @@ export function measureAndCacheTextWidth(font, text, cache) {
|
||||
if (text in cache) {
|
||||
return cache[text];
|
||||
}
|
||||
const width = measureTextWidth(font, text);
|
||||
const width = text
|
||||
.split('\n')
|
||||
.reduce((prev, curr) => Math.max(prev, measureTextWidth(font, curr)), 0);
|
||||
cache[text] = width;
|
||||
return width;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user