MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / drawRichText

Function drawRichText

libs/echarts/echarts-en.simple.js:8604–8678  ·  view source on GitHub ↗
(hostEl, ctx, contentBlock, style, rect)

Source from the content-addressed store, hash-verified

8602}
8603
8604function drawRichText(hostEl, ctx, contentBlock, style, rect) {
8605 var contentWidth = contentBlock.width;
8606 var outerWidth = contentBlock.outerWidth;
8607 var outerHeight = contentBlock.outerHeight;
8608 var textPadding = style.textPadding;
8609
8610 var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
8611 var baseX = boxPos.baseX;
8612 var baseY = boxPos.baseY;
8613 var textAlign = boxPos.textAlign;
8614 var textVerticalAlign = boxPos.textVerticalAlign;
8615
8616 // Origin of textRotation should be the base point of text drawing.
8617 applyTextRotation(ctx, style, rect, baseX, baseY);
8618
8619 var boxX = adjustTextX(baseX, outerWidth, textAlign);
8620 var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
8621 var xLeft = boxX;
8622 var lineTop = boxY;
8623 if (textPadding) {
8624 xLeft += textPadding[3];
8625 lineTop += textPadding[0];
8626 }
8627 var xRight = xLeft + contentWidth;
8628
8629 needDrawBackground(style) && drawBackground(
8630 hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight
8631 );
8632
8633 for (var i = 0; i < contentBlock.lines.length; i++) {
8634 var line = contentBlock.lines[i];
8635 var tokens = line.tokens;
8636 var tokenCount = tokens.length;
8637 var lineHeight = line.lineHeight;
8638 var usedWidth = line.width;
8639
8640 var leftIndex = 0;
8641 var lineXLeft = xLeft;
8642 var lineXRight = xRight;
8643 var rightIndex = tokenCount - 1;
8644 var token;
8645
8646 while (
8647 leftIndex < tokenCount
8648 && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')
8649 ) {
8650 placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
8651 usedWidth -= token.width;
8652 lineXLeft += token.width;
8653 leftIndex++;
8654 }
8655
8656 while (
8657 rightIndex >= 0
8658 && (token = tokens[rightIndex], token.textAlign === 'right')
8659 ) {
8660 placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
8661 usedWidth -= token.width;

Callers 1

renderRichTextFunction · 0.70

Calls 7

getBoxPositionFunction · 0.70
applyTextRotationFunction · 0.70
adjustTextXFunction · 0.70
adjustTextYFunction · 0.70
needDrawBackgroundFunction · 0.70
drawBackgroundFunction · 0.70
placeTokenFunction · 0.70

Tested by

no test coverage detected