| 434 | } |
| 435 | |
| 436 | std::shared_ptr<Graphic> RenderTextBackground(ID assetID, |
| 437 | const std::vector<std::vector<GlyphHandle>>& lines, |
| 438 | const TextDocument* textDocument) { |
| 439 | float strokeWidth = textDocument->strokeWidth; |
| 440 | auto margin = textDocument->fontSize * 0.4f; |
| 441 | if (margin < strokeWidth) { |
| 442 | margin = strokeWidth; |
| 443 | } |
| 444 | auto isVertical = textDocument->direction == TextDirection::Vertical; |
| 445 | float lineTop = 0, lineBottom = 0; |
| 446 | for (auto& line : lines) { |
| 447 | for (auto& glyph : line) { |
| 448 | if (isVertical) { |
| 449 | lineTop = std::min(lineTop, -glyph->getBounds().right); |
| 450 | lineBottom = std::max(lineBottom, -glyph->getBounds().left); |
| 451 | } else { |
| 452 | lineTop = std::min(lineTop, glyph->getBounds().top); |
| 453 | lineBottom = std::max(lineBottom, glyph->getBounds().bottom); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | auto backgroundPath = RenderBackgroundPath(lines, margin, lineTop, lineBottom, isVertical); |
| 459 | auto bounds = backgroundPath.getBounds(); |
| 460 | float maxRadius = std::min(bounds.width(), bounds.height()) / 3.0f; |
| 461 | if (maxRadius >= 25.0f) { |
| 462 | maxRadius = 25.0f; |
| 463 | } |
| 464 | auto effect = tgfx::PathEffect::MakeCorner(maxRadius); |
| 465 | if (effect) { |
| 466 | effect->filterPath(&backgroundPath); |
| 467 | } |
| 468 | auto graphic = Shape::MakeFrom(assetID, backgroundPath, ToTGFX(textDocument->backgroundColor)); |
| 469 | auto modifier = |
| 470 | Modifier::MakeBlend(ToAlpha(textDocument->backgroundAlpha), tgfx::BlendMode::SrcOver); |
| 471 | return Graphic::MakeCompose(graphic, modifier); |
| 472 | } |
| 473 | |
| 474 | static std::vector<GlyphHandle> BuildGlyphs(const TextDocument* textDocument) { |
| 475 | TextPaint textPaint = {}; |
no test coverage detected