Exemplo n.º 1
0
void RenderCombineText::charactersToRender(int start, const UChar*& characters, int& length) const
{
    if (m_isCombined) {
        length = originalText()->length();
        characters = originalText()->characters();
        return;
    }
 
    characters = text()->characters() + start;
}
Exemplo n.º 2
0
void RenderTextFragment::transformText()
{
    // Don't reset first-letter here because we are only transforming the truncated fragment.
    String textToTransform = originalText();
    if (!textToTransform.isNull())
        RenderText::setText(textToTransform, true);
}
Exemplo n.º 3
0
size_t FrTextSpan::wordCountOriginal() const
{
   char *words = originalText() ;
   size_t count = word_count(words) ;
   FrFree(words) ;
   return count ;
}
Exemplo n.º 4
0
void RenderQuote::updateDepth()
{
    ASSERT(m_isAttached);
    int depth = 0;
    if (m_previous) {
        depth = m_previous->m_depth;
        if (depth < 0)
            depth = 0;
        switch (m_previous->m_type) {
        case OPEN_QUOTE:
        case NO_OPEN_QUOTE:
            depth++;
            break;
        case CLOSE_QUOTE:
        case NO_CLOSE_QUOTE:
            break;
        }
    }
    switch (m_type) {
    case OPEN_QUOTE:
    case NO_OPEN_QUOTE:
        break;
    case CLOSE_QUOTE:
    case NO_CLOSE_QUOTE:
        depth--;
        break;
    }
    if (m_depth == depth)
        return;
    m_depth = depth;
    setText(originalText());
}
Exemplo n.º 5
0
void LayoutTextFragment::transformText() {
  // Note, we have to call LayoutText::setText here because, if we use our
  // version we will, potentially, screw up the first-letter settings where
  // we only use portions of the string.
  if (RefPtr<StringImpl> textToTransform = originalText())
    LayoutText::setText(textToTransform.release(), true);
}
Exemplo n.º 6
0
char *FrTextSpan::initialText() const
{
   const FrObject *txt = getMetaData(init_text_tag) ;
   if (txt && txt->consp() && ((FrList*)txt)->first() &&
       ((FrList*)txt)->first()->stringp())
      txt = ((FrList*)txt)->first() ;
   const char *printed = FrPrintableName(txt) ;
   return printed ? FrDupString(printed) : originalText() ;
}
void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    // Skip RenderText's possible layout scheduling on style change
    RenderObject::styleDidChange(diff, oldStyle);
    
    // FIXME: SVG text is apparently always transformed?
    if (RefPtr<StringImpl> textToTransform = originalText())
        setText(textToTransform.release(), true);
}
Exemplo n.º 8
0
void RenderCombineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    setStyleInternal(RenderStyle::clone(style()));
    RenderText::styleDidChange(diff, oldStyle);

    if (m_isCombined)
        RenderText::setTextInternal(originalText()); // This RenderCombineText has been combined once. Restore the original text for the next combineText().

    setNeedsFontUpdate(true);
}
void RenderCombineText::getStringToRender(int start, StringView& string, int& length) const
{
    ASSERT(start >= 0);
    if (m_isCombined) {
        string = StringView(originalText());
        length = string.length();
        return;
    }

    string = text().createView(start, length);
}
Exemplo n.º 10
0
void RenderCombineText::getStringToRender(int start, String& string, int& length) const
{
    ASSERT(start >= 0);
    if (m_isCombined) {
        string = originalText();
        length = string.length();
        return;
    }
 
    string = text();
    string = string.substringSharingImpl(static_cast<unsigned>(start), length);
}
Exemplo n.º 11
0
void RenderCombineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    // FIXME: This is pretty hackish.
    m_combineFontStyle = RenderStyle::clone(style());

    RenderText::styleDidChange(diff, oldStyle);

    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;
}
Exemplo n.º 12
0
void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    RenderText::styleDidChange(diff, oldStyle);
    updateScaledFont();

    bool newPreserves = style().whiteSpace() == PRE;
    bool oldPreserves = oldStyle ? oldStyle->whiteSpace() == PRE : false;
    if (oldPreserves && !newPreserves) {
        setText(applySVGWhitespaceRules(originalText(), false), true);
        return;
    }

    if (!oldPreserves && newPreserves) {
        setText(applySVGWhitespaceRules(originalText(), true), true);
        return;
    }

    if (diff != StyleDifferenceLayout)
        return;

    // The text metrics may be influenced by style changes.
    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
        textAncestor->subtreeStyleDidChange(this);
}
Exemplo n.º 13
0
void RenderCombineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    // FIXME: This is pretty hackish.
    m_combineFontStyle = RenderStyle::clone(&style());

    RenderText::styleDidChange(diff, oldStyle);

    if (m_isCombined && selfNeedsLayout()) {
        // Layouts cause the text to be recombined; therefore, only only un-combine when the style diff causes a layout.
        RenderText::setRenderedText(originalText()); // This RenderCombineText has been combined once. Restore the original text for the next combineText().
        m_isCombined = false;
    }

    m_needsFontUpdate = true;
}
Exemplo n.º 14
0
void RenderCounter::computePreferredLogicalWidths(float lead)
{
#ifndef NDEBUG
    // FIXME: We shouldn't be modifying the tree in computePreferredLogicalWidths.
    // Instead, we should properly hook the appropriate changes in the DOM and modify
    // the render tree then. When that's done, we also won't need to override
    // computePreferredLogicalWidths at all.
    // https://bugs.webkit.org/show_bug.cgi?id=104829
    SetLayoutNeededForbiddenScope layoutForbiddenScope(this, false);
#endif

    setTextInternal(originalText());

    RenderText::computePreferredLogicalWidths(lead);
}
Exemplo n.º 15
0
void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    RenderText::styleDidChange(diff, oldStyle);

    if (diff == StyleDifferenceLayout) {
        // The text metrics may be influenced by style changes.
        if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
            textRenderer->setNeedsPositioningValuesUpdate();
    }

    const RenderStyle* newStyle = style();
    if (!newStyle || newStyle->whiteSpace() != PRE)
        return;

    if (!oldStyle || oldStyle->whiteSpace() != PRE)
        setText(applySVGWhitespaceRules(originalText(), true), true);
}
Exemplo n.º 16
0
void LayoutSVGInlineText::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle)
{
    LayoutText::styleDidChange(diff, oldStyle);
    updateScaledFont();

    bool newPreserves = style() ? style()->whiteSpace() == PRE : false;
    bool oldPreserves = oldStyle ? oldStyle->whiteSpace() == PRE : false;
    if (oldPreserves != newPreserves) {
        setText(originalText(), true);
        return;
    }

    if (!diff.needsFullLayout())
        return;

    // The text metrics may be influenced by style changes.
    if (LayoutSVGText* textLayoutObject = LayoutSVGText::locateLayoutSVGTextAncestor(this))
        textLayoutObject->setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::StyleChange);
}
Exemplo n.º 17
0
void RenderCombineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    // FIXME: This is pretty hackish.
    // Only cache a new font style if our old one actually changed. We do this to avoid
    // clobbering width variants and shrink-to-fit changes, since we won't recombine when
    // the font doesn't change.
    if (!oldStyle || oldStyle->fontCascade() != style().fontCascade())
        m_combineFontStyle = RenderStyle::clone(&style());

    RenderText::styleDidChange(diff, oldStyle);

    if (m_isCombined && selfNeedsLayout()) {
        // Layouts cause the text to be recombined; therefore, only only un-combine when the style diff causes a layout.
        RenderText::setRenderedText(originalText()); // This RenderCombineText has been combined once. Restore the original text for the next combineText().
        m_isCombined = false;
    }

    m_needsFontUpdate = true;
}
Exemplo n.º 18
0
void RenderQuote::updateDepth()
{
    ASSERT(m_attached);
    int oldDepth = m_depth;
    m_depth = 0;
    if (m_previous) {
        m_depth = m_previous->m_depth;
        switch (m_previous->m_type) {
        case OPEN_QUOTE:
        case NO_OPEN_QUOTE:
            m_depth++;
            break;
        case CLOSE_QUOTE:
        case NO_CLOSE_QUOTE:
            if (m_depth)
                m_depth--;
            break;
        }
    }
    if (oldDepth != m_depth)
        setText(originalText());
}
Exemplo n.º 19
0
void RenderCounter::computePreferredLogicalWidths(float lead)
{
    setTextInternal(originalText());
    RenderText::computePreferredLogicalWidths(lead);
}
Exemplo n.º 20
0
void RenderCounter::updateCounter()
{
    setTextInternal(originalText());
}
Exemplo n.º 21
0
void RenderCounter::calcPrefWidths(int lead)
{
    setTextInternal(originalText());
    RenderText::calcPrefWidths(lead);
}
Exemplo n.º 22
0
char *FrTextSpan::getText() const
{
   return m_text ? FrDupString(m_text) : originalText() ;
}
Exemplo n.º 23
0
void RenderQuote::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    RenderText::styleDidChange(diff, oldStyle);
    setText(originalText());
}
Exemplo n.º 24
0
void LayoutCounter::updateCounter()
{
    setText(originalText());
}
Exemplo n.º 25
0
void RenderCombineText::combineText()
{
    if (!m_needsFontUpdate)
        return;

    // An ancestor element may trigger us to lay out again, even when we're already combined.
    if (m_isCombined)
        RenderText::setRenderedText(originalText());

    m_isCombined = false;
    m_needsFontUpdate = false;

    // CSS3 spec says text-combine works only in vertical writing mode.
    if (style().isHorizontalWritingMode())
        return;

    auto description = originalFont().fontDescription();
    float emWidth = description.computedSize() * textCombineMargin;
    bool shouldUpdateFont = false;

    description.setOrientation(Horizontal); // We are going to draw combined text horizontally.
    
    GlyphOverflow glyphOverflow;
    glyphOverflow.computeBounds = true;
    
    float combinedTextWidth = width(0, textLength(), originalFont(), 0, nullptr, &glyphOverflow);

    float bestFitDelta = combinedTextWidth - emWidth;
    auto bestFitDescription = description;

    m_isCombined = combinedTextWidth <= emWidth;
    
    FontSelector* fontSelector = style().fontCascade().fontSelector();
    
    if (m_isCombined)
        shouldUpdateFont = m_combineFontStyle->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) {
            description.setWidthVariant(widthVariants[i]); // When modifying this, make sure to keep it in sync with FontPlatformData::isForTextCombine()!

            FontCascade compressedFont(description, style().fontCascade().letterSpacing(), style().fontCascade().wordSpacing());
            compressedFont.update(fontSelector);
            
            glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
            float runWidth = RenderText::width(0, textLength(), compressedFont, 0, nullptr, &glyphOverflow);
            if (runWidth <= emWidth) {
                combinedTextWidth = runWidth;
                m_isCombined = true;

                // Replace my font with the new one.
                shouldUpdateFont = m_combineFontStyle->setFontDescription(description);
                break;
            }
            
            float widthDelta = runWidth - emWidth;
            if (widthDelta < bestFitDelta) {
                bestFitDelta = widthDelta;
                bestFitDescription = description;
            }
        }
    }

    if (!m_isCombined) {
        float scaleFactor = std::max(0.4f, emWidth / (emWidth + bestFitDelta));
        float originalSize = bestFitDescription.computedSize();
        do {
            float computedSize = originalSize * scaleFactor;
            bestFitDescription.setComputedSize(computedSize);
            shouldUpdateFont = m_combineFontStyle->setFontDescription(bestFitDescription);
        
            FontCascade compressedFont(bestFitDescription, style().fontCascade().letterSpacing(), style().fontCascade().wordSpacing());
            compressedFont.update(fontSelector);
            
            glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
            float runWidth = RenderText::width(0, textLength(), compressedFont, 0, nullptr, &glyphOverflow);
            if (runWidth <= emWidth) {
                combinedTextWidth = runWidth;
                m_isCombined = true;
                break;
            }
            scaleFactor -= 0.05f;
        } while (scaleFactor >= 0.4f);
    }

    if (shouldUpdateFont)
        m_combineFontStyle->fontCascade().update(fontSelector);

    if (m_isCombined) {
        static NeverDestroyed<String> objectReplacementCharacterString(&objectReplacementCharacter, 1);
        RenderText::setRenderedText(objectReplacementCharacterString.get());
        m_combinedTextWidth = combinedTextWidth;
        m_combinedTextAscent = glyphOverflow.top;
        m_combinedTextDescent = glyphOverflow.bottom;
    }
}