Move drawText along line to executor

This commit is contained in:
Guillaume Beraudo
2018-11-14 18:20:38 +01:00
parent 0ece0fb002
commit c0df61468f
2 changed files with 35 additions and 33 deletions

View File

@@ -8,7 +8,7 @@ import {intersects} from '../../extent.js';
import {matchingChunk} from '../../geom/flat/straightchunk.js';
import GeometryType from '../../geom/GeometryType.js';
import {CANVAS_LINE_DASH} from '../../has.js';
import {labelCache, measureTextWidth, measureTextWidths, defaultTextAlign, measureTextHeight, defaultPadding, defaultLineCap, defaultLineDashOffset, defaultLineDash, defaultLineJoin, defaultFillStyle, checkFont, defaultFont, defaultLineWidth, defaultMiterLimit, defaultStrokeStyle, defaultTextBaseline} from '../canvas.js';
import {labelCache, measureTextWidths, defaultTextAlign, measureTextHeight, defaultPadding, defaultLineCap, defaultLineDashOffset, defaultLineDash, defaultLineJoin, defaultFillStyle, checkFont, defaultFont, defaultLineWidth, defaultMiterLimit, defaultStrokeStyle, defaultTextBaseline} from '../canvas.js';
import CanvasInstruction from './Instruction.js';
import CanvasInstructionsBuilder from './InstructionsBuilder.js';
import {TEXT_ALIGN} from '../replay.js';
@@ -119,12 +119,6 @@ class CanvasTextBuilder extends CanvasInstructionsBuilder {
*/
this.strokeKey_ = '';
/**
* @private
* @type {Object<string, Object<string, number>>}
*/
this.widths_ = {};
labelCache.prune();
}
@@ -409,35 +403,19 @@ class CanvasTextBuilder extends CanvasInstructionsBuilder {
const offsetY = this.textOffsetY_ * pixelRatio;
const text = this.text_;
const font = textState.font;
const textScale = textState.scale;
const strokeWidth = strokeState ? strokeState.lineWidth * textScale / 2 : 0;
let widths = this.widths_[font];
if (!widths) {
this.widths_[font] = widths = {};
}
this.instructions.push([CanvasInstruction.DRAW_CHARS,
begin, end, baseline, declutterGroup,
textState.overflow, fillKey, textState.maxAngle,
function(text) {
let width = widths[text];
if (!width) {
width = widths[text] = measureTextWidth(font, text);
}
return width * textScale * pixelRatio;
},
pixelRatio,
offsetY, strokeKey, strokeWidth * pixelRatio, text, textKey, 1
]);
this.hitDetectionInstructions.push([CanvasInstruction.DRAW_CHARS,
begin, end, baseline, declutterGroup,
textState.overflow, fillKey, textState.maxAngle,
function(text) {
let width = widths[text];
if (!width) {
width = widths[text] = measureTextWidth(font, text);
}
return width * textScale;
},
1,
offsetY, strokeKey, strokeWidth, text, textKey, 1 / pixelRatio
]);
}