(hostEl, ctx, text, style, rect, prevEl)
| 8431 | // Avoid setting to ctx according to prevEl if possible for |
| 8432 | // performance in scenarios of large amount text. |
| 8433 | function renderPlainText(hostEl, ctx, text, style, rect, prevEl) { |
| 8434 | 'use strict'; |
| 8435 | |
| 8436 | var needDrawBg = needDrawBackground(style); |
| 8437 | |
| 8438 | var prevStyle; |
| 8439 | var checkCache = false; |
| 8440 | var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT; |
| 8441 | |
| 8442 | // Only take and check cache for `Text` el, but not RectText. |
| 8443 | if (prevEl !== WILL_BE_RESTORED) { |
| 8444 | if (prevEl) { |
| 8445 | prevStyle = prevEl.style; |
| 8446 | checkCache = !needDrawBg && cachedByMe && prevStyle; |
| 8447 | } |
| 8448 | |
| 8449 | // Prevent from using cache in `Style::bind`, because of the case: |
| 8450 | // ctx property is modified by other properties than `Style::bind` |
| 8451 | // used, and Style::bind is called next. |
| 8452 | ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT; |
| 8453 | } |
| 8454 | // Since this will be restored, prevent from using these props to check cache in the next |
| 8455 | // entering of this method. But do not need to clear other cache like `Style::bind`. |
| 8456 | else if (cachedByMe) { |
| 8457 | ctx.__attrCachedBy = ContextCachedBy.NONE; |
| 8458 | } |
| 8459 | |
| 8460 | var styleFont = style.font || DEFAULT_FONT; |
| 8461 | // PENDING |
| 8462 | // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically |
| 8463 | // we can make font cache on ctx, which can cache for text el that are discontinuous. |
| 8464 | // But layer save/restore needed to be considered. |
| 8465 | // if (styleFont !== ctx.__fontCache) { |
| 8466 | // ctx.font = styleFont; |
| 8467 | // if (prevEl !== WILL_BE_RESTORED) { |
| 8468 | // ctx.__fontCache = styleFont; |
| 8469 | // } |
| 8470 | // } |
| 8471 | if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) { |
| 8472 | ctx.font = styleFont; |
| 8473 | } |
| 8474 | |
| 8475 | // Use the final font from context-2d, because the final |
| 8476 | // font might not be the style.font when it is illegal. |
| 8477 | // But get `ctx.font` might be time consuming. |
| 8478 | var computedFont = hostEl.__computedFont; |
| 8479 | if (hostEl.__styleFont !== styleFont) { |
| 8480 | hostEl.__styleFont = styleFont; |
| 8481 | computedFont = hostEl.__computedFont = ctx.font; |
| 8482 | } |
| 8483 | |
| 8484 | var textPadding = style.textPadding; |
| 8485 | var textLineHeight = style.textLineHeight; |
| 8486 | |
| 8487 | var contentBlock = hostEl.__textCotentBlock; |
| 8488 | if (!contentBlock || hostEl.__dirtyText) { |
| 8489 | contentBlock = hostEl.__textCotentBlock = parsePlainText( |
| 8490 | text, computedFont, textPadding, textLineHeight, style.truncate |
no test coverage detected