Add textFitWidth and textFitHeight Properties to Sprites (#2780)

Co-authored-by: Xiaolian Qin <xiaoq@microsoft.com>
This commit is contained in:
qqz003
2024-09-13 21:02:02 +08:00
committed by GitHub
parent 814e1015a8
commit cb38119451
58 changed files with 2116 additions and 103 deletions

View File

@@ -76,9 +76,6 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon,
const uint16_t imageWidth = image.paddedRect.w - 2 * border;
const uint16_t imageHeight = image.paddedRect.h - 2 * border;
const float iconWidth = shapedIcon.right() - shapedIcon.left();
const float iconHeight = shapedIcon.bottom() - shapedIcon.top();
const ImageStretches stretchXFull{{0.0f, imageWidth}};
const ImageStretches stretchYFull{{0.0f, imageHeight}};
const ImageStretches& stretchX = !image.stretchX.empty() ? image.stretchX : stretchXFull;
@@ -98,16 +95,23 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon,
float fixedOffsetY = 0;
float fixedContentHeight = fixedHeight;
auto icon = shapedIcon;
if (hasIconTextFit && image.content) {
auto& content = *image.content;
const auto& content = *image.content;
const auto contentWidth = content.right - content.left;
const auto contentHeight = content.bottom - content.top;
if (image.textFitWidth || image.textFitHeight) {
icon = icon.applyTextFit();
}
stretchOffsetX = sumWithinRange(stretchX, 0, content.left);
stretchOffsetY = sumWithinRange(stretchY, 0, content.top);
stretchContentWidth = sumWithinRange(stretchX, content.left, content.right);
stretchContentHeight = sumWithinRange(stretchY, content.top, content.bottom);
fixedOffsetX = content.left - stretchOffsetX;
fixedOffsetY = content.top - stretchOffsetY;
fixedContentWidth = content.right - content.left - stretchContentWidth;
fixedContentHeight = content.bottom - content.top - stretchContentHeight;
fixedContentWidth = contentWidth - stretchContentWidth;
fixedContentHeight = contentHeight - stretchContentHeight;
}
std::optional<std::array<float, 4>> matrix{std::nullopt};
@@ -118,21 +122,22 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon,
matrix = std::array<float, 4>{{angle_cos, -angle_sin, angle_sin, angle_cos}};
}
const float iconLeft = icon.left();
const float iconTop = icon.top();
const float iconWidth = icon.right() - iconLeft;
const float iconHeight = icon.bottom() - iconTop;
auto makeBox = [&](Cut left, Cut top, Cut right, Cut bottom) {
const float leftEm = getEmOffset(
left.stretch - stretchOffsetX, stretchContentWidth, iconWidth, shapedIcon.left());
const float leftEm = getEmOffset(left.stretch - stretchOffsetX, stretchContentWidth, iconWidth, iconLeft);
const float leftPx = getPxOffset(left.fixed - fixedOffsetX, fixedContentWidth, left.stretch, stretchWidth);
const float topEm = getEmOffset(
top.stretch - stretchOffsetY, stretchContentHeight, iconHeight, shapedIcon.top());
const float topEm = getEmOffset(top.stretch - stretchOffsetY, stretchContentHeight, iconHeight, iconTop);
const float topPx = getPxOffset(top.fixed - fixedOffsetY, fixedContentHeight, top.stretch, stretchHeight);
const float rightEm = getEmOffset(
right.stretch - stretchOffsetX, stretchContentWidth, iconWidth, shapedIcon.left());
const float rightEm = getEmOffset(right.stretch - stretchOffsetX, stretchContentWidth, iconWidth, iconLeft);
const float rightPx = getPxOffset(right.fixed - fixedOffsetX, fixedContentWidth, right.stretch, stretchWidth);
const float bottomEm = getEmOffset(
bottom.stretch - stretchOffsetY, stretchContentHeight, iconHeight, shapedIcon.top());
const float bottomEm = getEmOffset(bottom.stretch - stretchOffsetY, stretchContentHeight, iconHeight, iconTop);
const float bottomPx = getPxOffset(
bottom.fixed - fixedOffsetY, fixedContentHeight, bottom.stretch, stretchHeight);