EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline(bool isVerticalText, const LayoutObject* textLayoutObject) const
{
    ASSERT(textLayoutObject);
    ASSERT(textLayoutObject->style());

    const SVGComputedStyle& style = textLayoutObject->style()->svgStyle();

    EDominantBaseline baseline = style.dominantBaseline();
    if (baseline == DB_AUTO) {
        if (isVerticalText)
            baseline = DB_CENTRAL;
        else
            baseline = DB_ALPHABETIC;
    }

    switch (baseline) {
    case DB_USE_SCRIPT:
        // TODO(fs): The dominant-baseline and the baseline-table components
        // are set by determining the predominant script of the character data
        // content.
        return AB_ALPHABETIC;
    case DB_NO_CHANGE:
        ASSERT(textLayoutObject->parent());
        return dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObject->parent());
    case DB_RESET_SIZE:
        ASSERT(textLayoutObject->parent());
        return dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObject->parent());
    case DB_IDEOGRAPHIC:
        return AB_IDEOGRAPHIC;
    case DB_ALPHABETIC:
        return AB_ALPHABETIC;
    case DB_HANGING:
        return AB_HANGING;
    case DB_MATHEMATICAL:
        return AB_MATHEMATICAL;
    case DB_CENTRAL:
        return AB_CENTRAL;
    case DB_MIDDLE:
        return AB_MIDDLE;
    case DB_TEXT_AFTER_EDGE:
        return AB_TEXT_AFTER_EDGE;
    case DB_TEXT_BEFORE_EDGE:
        return AB_TEXT_BEFORE_EDGE;
    default:
        ASSERT_NOT_REACHED();
        return AB_AUTO;
    }
}
Пример #2
0
float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVerticalText, const RenderObject* textRenderer) const
{
    ASSERT(textRenderer);
    ASSERT(textRenderer->style());
    ASSERT(textRenderer->style()->svgStyle());
    ASSERT(textRenderer->parent());

    const RenderObject* textRendererParent = textRenderer->parent();
    ASSERT(textRendererParent);

    EAlignmentBaseline baseline = textRenderer->style()->svgStyle()->alignmentBaseline();
    if (baseline == AB_AUTO) {
        baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRendererParent);
        ASSERT(baseline != AB_AUTO);
    }

    const FontMetrics& fontMetrics = m_font.fontMetrics();

    // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
    switch (baseline) {
    case AB_BASELINE:
        return dominantBaselineToAlignmentBaseline(isVerticalText, textRendererParent);
    case AB_BEFORE_EDGE:
    case AB_TEXT_BEFORE_EDGE:
        return fontMetrics.floatAscent();
    case AB_MIDDLE:
        return fontMetrics.xHeight() / 2;
    case AB_CENTRAL:
        return (fontMetrics.floatAscent() - fontMetrics.floatDescent()) / 2;
    case AB_AFTER_EDGE:
    case AB_TEXT_AFTER_EDGE:
    case AB_IDEOGRAPHIC:
        return fontMetrics.floatDescent();
    case AB_ALPHABETIC:
        return 0;
    case AB_HANGING:
        return fontMetrics.floatAscent() * 8 / 10.f;
    case AB_MATHEMATICAL:
        return fontMetrics.floatAscent() / 2;
    default:
        ASSERT_NOT_REACHED();
        return 0;
    }
}
float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVerticalText, const LayoutObject* textLayoutObject) const
{
    ASSERT(textLayoutObject);
    ASSERT(textLayoutObject->style());
    ASSERT(textLayoutObject->parent());

    const LayoutObject* textLayoutObjectParent = textLayoutObject->parent();
    ASSERT(textLayoutObjectParent);

    EAlignmentBaseline baseline = textLayoutObject->style()->svgStyle().alignmentBaseline();
    if (baseline == AB_AUTO || baseline == AB_BASELINE) {
        baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObjectParent);
        ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
    }

    const FontMetrics& fontMetrics = m_font.fontMetrics();
    float ascent = fontMetrics.floatAscent() / m_effectiveZoom;
    float descent = fontMetrics.floatDescent() / m_effectiveZoom;
    float xheight = fontMetrics.xHeight() / m_effectiveZoom;

    // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
    switch (baseline) {
    case AB_BEFORE_EDGE:
    case AB_TEXT_BEFORE_EDGE:
        return ascent;
    case AB_MIDDLE:
        return xheight / 2;
    case AB_CENTRAL:
        return (ascent - descent) / 2;
    case AB_AFTER_EDGE:
    case AB_TEXT_AFTER_EDGE:
    case AB_IDEOGRAPHIC:
        return -descent;
    case AB_ALPHABETIC:
        return 0;
    case AB_HANGING:
        return ascent * 8 / 10.f;
    case AB_MATHEMATICAL:
        return ascent / 2;
    case AB_BASELINE:
    default:
        ASSERT_NOT_REACHED();
        return 0;
    }
}