Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1510)

Unified Diff: Source/core/rendering/RenderCombineText.cpp

Issue 881133003: Revert of text-combine should scale rather than fall back to none when wide (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/RenderCombineText.cpp
diff --git a/Source/core/rendering/RenderCombineText.cpp b/Source/core/rendering/RenderCombineText.cpp
index 4cd0bd957110659eee9fe39b92d3f44d5bbdac5f..fb58e1ab932675aedca302c19fcd03567c36ee0b 100644
--- a/Source/core/rendering/RenderCombineText.cpp
+++ b/Source/core/rendering/RenderCombineText.cpp
@@ -22,18 +22,16 @@
#include "core/rendering/RenderCombineText.h"
#include "core/rendering/TextRunConstructor.h"
-#include "platform/graphics/GraphicsContext.h"
namespace blink {
const float textCombineMargin = 1.1f; // Allow em + 10% margin
RenderCombineText::RenderCombineText(Node* node, PassRefPtr<StringImpl> string)
- : RenderText(node, string)
- , m_combinedTextWidth(0)
- , m_scaleX(1.0f)
- , m_isCombined(false)
- , m_needsFontUpdate(false)
+ : RenderText(node, string)
+ , m_combinedTextWidth(0)
+ , m_isCombined(false)
+ , m_needsFontUpdate(false)
{
}
@@ -42,15 +40,19 @@
setStyleInternal(RenderStyle::clone(style()));
RenderText::styleDidChange(diff, oldStyle);
- updateIsCombinedAndText();
+ if (m_isCombined) {
+ RenderText::setTextInternal(originalText()); // This RenderCombineText has been combined once. Restore the original text for the next combineText().
+ m_isCombined = false;
+ }
+
+ m_needsFontUpdate = true;
}
void RenderCombineText::setTextInternal(PassRefPtr<StringImpl> text)
{
RenderText::setTextInternal(text);
- m_isCombined = false; // flag that text() holds the text to render
- updateIsCombinedAndText();
+ m_needsFontUpdate = true;
}
float RenderCombineText::width(unsigned from, unsigned length, const Font& font, float xPosition, TextDirection direction, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
@@ -69,26 +71,13 @@
void RenderCombineText::adjustTextOrigin(FloatPoint& textOrigin, const FloatRect& boxRect) const
{
- ASSERT(!m_needsFontUpdate);
- if (!m_isCombined)
- return;
- float renderingWidth = m_combinedTextWidth / m_scaleX;
- textOrigin.move(boxRect.height() / 2 - renderingWidth / 2, style()->font().fontDescription().computedPixelSize());
-}
-
-void RenderCombineText::transform(GraphicsContext& context, const FloatRect& boxRect) const
-{
- ASSERT(!m_needsFontUpdate);
- ASSERT(isTransformNeeded());
- auto centerX = boxRect.x() + boxRect.width() / 2;
- AffineTransform transform(m_scaleX, 0, 0, 1, centerX * (1 - m_scaleX), 0);
- context.concatCTM(transform);
+ if (m_isCombined)
+ textOrigin.move(boxRect.height() / 2 - ceilf(m_combinedTextWidth) / 2, style()->font().fontDescription().computedPixelSize());
}
void RenderCombineText::getStringToRender(int start, StringView& string, int& length) const
{
ASSERT(start >= 0);
- ASSERT(!m_needsFontUpdate);
if (m_isCombined) {
string = StringView(m_renderingText.impl());
length = string.length();
@@ -98,54 +87,36 @@
string = text().createView(start, length);
}
-void RenderCombineText::updateIsCombinedAndText()
-{
- // CSS3 spec says text-combine works only in vertical writing mode.
- bool shouldCombine = !style()->isHorizontalWritingMode()
- // Nothing to combine.
- && !(m_isCombined ? m_renderingText.isEmpty() : hasEmptyText());
- if (shouldCombine == m_isCombined)
- return;
-
- m_isCombined = shouldCombine;
-
- if (!shouldCombine) {
- RenderText::setTextInternal(m_renderingText.impl());
- m_renderingText.releaseImpl();
- return;
- }
- DEFINE_STATIC_LOCAL(String, objectReplacementCharacterString, (&objectReplacementCharacter, 1));
- m_renderingText = text();
- RenderText::setTextInternal(objectReplacementCharacterString.impl());
- m_needsFontUpdate = true;
-}
-
-void RenderCombineText::updateFont()
+void RenderCombineText::combineText()
{
if (!m_needsFontUpdate)
return;
+ m_isCombined = false;
m_needsFontUpdate = false;
- if (!m_isCombined)
+ // CSS3 spec says text-combine works only in vertical writing mode.
+ if (style()->isHorizontalWritingMode())
return;
- TextRun run = constructTextRun(this, originalFont(), m_renderingText, style(), style()->direction());
+ // Nothing to combine.
+ if (hasEmptyText())
+ return;
+
+ TextRun run = constructTextRun(this, originalFont(), this, style(), style()->direction());
FontDescription description = originalFont().fontDescription();
- float emWidth = description.computedSize();
- if (!(style()->textDecorationsInEffect() & (TextDecorationUnderline | TextDecorationOverline)))
- emWidth *= textCombineMargin;
+ float emWidth = description.computedSize() * textCombineMargin;
+ bool shouldUpdateFont = false;
description.setOrientation(Horizontal); // We are going to draw combined text horizontally.
m_combinedTextWidth = originalFont().width(run);
+ m_isCombined = m_combinedTextWidth <= emWidth;
FontSelector* fontSelector = style()->font().fontSelector();
- bool shouldUpdateFont = style()->setFontDescription(description); // Need to change font orientation to horizontal.
-
- if (m_combinedTextWidth <= emWidth) {
- m_scaleX = 1.0f;
- } else {
+ if (m_isCombined)
+ shouldUpdateFont = style()->setFontDescription(description); // Need to change font orientation to horizontal.
+ else {
// Need to try compressed glyphs.
static const FontWidthVariant widthVariants[] = { HalfWidth, ThirdWidth, QuarterWidth };
for (size_t i = 0 ; i < WTF_ARRAY_LENGTH(widthVariants) ; ++i) {
@@ -155,25 +126,26 @@
float runWidth = compressedFont.width(run);
if (runWidth <= emWidth) {
m_combinedTextWidth = runWidth;
+ m_isCombined = true;
// Replace my font with the new one.
shouldUpdateFont = style()->setFontDescription(description);
break;
}
}
+ }
- // If width > ~1em, shrink to fit within ~1em, otherwise render without scaling (no expansion)
- // http://dev.w3.org/csswg/css-writing-modes-3/#text-combine-compression
- if (m_combinedTextWidth > emWidth) {
- m_scaleX = emWidth / m_combinedTextWidth;
- m_combinedTextWidth = emWidth;
- } else {
- m_scaleX = 1.0f;
- }
- }
+ if (!m_isCombined)
+ shouldUpdateFont = style()->setFontDescription(originalFont().fontDescription());
if (shouldUpdateFont)
style()->font().update(fontSelector);
+
+ if (m_isCombined) {
+ DEFINE_STATIC_LOCAL(String, objectReplacementCharacterString, (&objectReplacementCharacter, 1));
+ m_renderingText = text();
+ RenderText::setTextInternal(objectReplacementCharacterString.impl());
+ }
}
} // namespace blink
« no previous file with comments | « Source/core/rendering/RenderCombineText.h ('k') | Source/core/rendering/line/BreakingContextInlineHeaders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698