Attachment #292359: use em-box as text frame height for bug #402473

View | Details | Raw Unified | Return to bug 402473
Collapse All | Expand All

(-)layout/generic/nsHTMLContainerFrame.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 100-116   nsDisplayTextDecoration::Paint(nsDisplay Link Here 
100
  nsCOMPtr<nsIFontMetrics> fm;
100
  nsCOMPtr<nsIFontMetrics> fm;
101
  nsLayoutUtils::GetFontMetricsForFrame(mFrame, getter_AddRefs(fm));
101
  nsLayoutUtils::GetFontMetricsForFrame(mFrame, getter_AddRefs(fm));
102
102
103
  nsPoint pt = aBuilder->ToReferenceFrame(mFrame);
103
  nsPoint pt = aBuilder->ToReferenceFrame(mFrame);
104
104
105
  // REVIEW: From nsHTMLContainerFrame::PaintTextDecorations
105
  // REVIEW: From nsHTMLContainerFrame::PaintTextDecorations
106
  nscoord ascent, offset, size;
106
  nscoord ascent, offset, size;
107
  nsHTMLContainerFrame* f = static_cast<nsHTMLContainerFrame*>(mFrame);
107
  nsHTMLContainerFrame* f = static_cast<nsHTMLContainerFrame*>(mFrame);
108
  fm->GetMaxAscent(ascent);
108
  fm->GetEmAscent(ascent);
109
  if (mDecoration != NS_STYLE_TEXT_DECORATION_LINE_THROUGH) {
109
  if (mDecoration != NS_STYLE_TEXT_DECORATION_LINE_THROUGH) {
110
    fm->GetUnderline(offset, size);
110
    fm->GetUnderline(offset, size);
111
    if (mDecoration == NS_STYLE_TEXT_DECORATION_UNDERLINE) {
111
    if (mDecoration == NS_STYLE_TEXT_DECORATION_UNDERLINE) {
112
      f->PaintTextDecorationLine(*aCtx, pt, mLine, mColor,
112
      f->PaintTextDecorationLine(*aCtx, pt, mLine, mColor,
113
                                 offset, ascent, size, mDecoration);
113
                                 offset, ascent, size, mDecoration);
114
    } else if (mDecoration == NS_STYLE_TEXT_DECORATION_OVERLINE) {
114
    } else if (mDecoration == NS_STYLE_TEXT_DECORATION_OVERLINE) {
115
      f->PaintTextDecorationLine(*aCtx, pt, mLine, mColor,
115
      f->PaintTextDecorationLine(*aCtx, pt, mLine, mColor,
116
                                 ascent, ascent, size, mDecoration);
116
                                 ascent, ascent, size, mDecoration);
(-)layout/generic/nsInlineFrame.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 561-578   nsInlineFrame::ReflowFrames(nsPresContex Link Here 
561
    // Do things the standard css2 way -- though it's hard to find it
561
    // Do things the standard css2 way -- though it's hard to find it
562
    // in the css2 spec! It's actually found in the css1 spec section
562
    // in the css2 spec! It's actually found in the css1 spec section
563
    // 4.4 (you will have to read between the lines to really see
563
    // 4.4 (you will have to read between the lines to really see
564
    // it).
564
    // it).
565
    //
565
    //
566
    // The height of our box is the sum of our font size plus the top
566
    // The height of our box is the sum of our font size plus the top
567
    // and bottom border and padding. The height of children do not
567
    // and bottom border and padding. The height of children do not
568
    // affect our height.
568
    // affect our height.
569
    fm->GetMaxAscent(aMetrics.ascent);
569
    fm->GetEmAscent(aMetrics.ascent);
570
    fm->GetHeight(aMetrics.height);
570
    fm->GetEmHeight(aMetrics.height);
571
    // Include the text-decoration lines to the height.
571
    // Include the text-decoration lines to the height.
572
    // Currently, only underline is overflowable.
572
    // Currently, only underline is overflowable.
573
    nscoord offset, size;
573
    nscoord offset, size;
574
    fm->GetUnderline(offset, size);
574
    fm->GetUnderline(offset, size);
575
    nscoord ascentAndUnderline =
575
    nscoord ascentAndUnderline =
576
      aPresContext->RoundAppUnitsToNearestDevPixels(aMetrics.ascent - offset) +
576
      aPresContext->RoundAppUnitsToNearestDevPixels(aMetrics.ascent - offset) +
577
      aPresContext->RoundAppUnitsToNearestDevPixels(size);
577
      aPresContext->RoundAppUnitsToNearestDevPixels(size);
578
    if (ascentAndUnderline > aMetrics.height)
578
    if (ascentAndUnderline > aMetrics.height)
(-)layout/generic/nsLineLayout.cpp (-6 / +6 lines)
Line     Link Here 
 Lines 1908-1938   nsLineLayout::VerticalAlignFrames(PerSpa Link Here 
1908
                pfd->mMargin.top;
1908
                pfd->mMargin.top;
1909
            }
1909
            }
1910
            pfd->mVerticalAlign = VALIGN_OTHER;
1910
            pfd->mVerticalAlign = VALIGN_OTHER;
1911
            break;
1911
            break;
1912
1912
1913
          case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
1913
          case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
1914
            // The top of the logical box is aligned with the top of
1914
            // The top of the logical box is aligned with the top of
1915
            // the parent elements text.
1915
            // the parent elements text.
1916
            fm->GetMaxAscent(parentAscent);
1916
            fm->GetEmAscent(parentAscent);
1917
            if (frameSpan) {
1917
            if (frameSpan) {
1918
              pfd->mBounds.y = baselineY - parentAscent -
1918
              pfd->mBounds.y = baselineY - parentAscent -
1919
                pfd->mBorderPadding.top + frameSpan->mTopLeading;
1919
                pfd->mBorderPadding.top + frameSpan->mTopLeading;
1920
            }
1920
            }
1921
            else {
1921
            else {
1922
              pfd->mBounds.y = baselineY - parentAscent + pfd->mMargin.top;
1922
              pfd->mBounds.y = baselineY - parentAscent + pfd->mMargin.top;
1923
            }
1923
            }
1924
            pfd->mVerticalAlign = VALIGN_OTHER;
1924
            pfd->mVerticalAlign = VALIGN_OTHER;
1925
            break;
1925
            break;
1926
1926
1927
          case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
1927
          case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
1928
            // The bottom of the logical box is aligned with the
1928
            // The bottom of the logical box is aligned with the
1929
            // bottom of the parent elements text.
1929
            // bottom of the parent elements text.
1930
            fm->GetMaxDescent(parentDescent);
1930
            fm->GetEmDescent(parentDescent);
1931
            if (frameSpan) {
1931
            if (frameSpan) {
1932
              pfd->mBounds.y = baselineY + parentDescent -
1932
              pfd->mBounds.y = baselineY + parentDescent -
1933
                pfd->mBounds.height + pfd->mBorderPadding.bottom -
1933
                pfd->mBounds.height + pfd->mBorderPadding.bottom -
1934
                frameSpan->mBottomLeading;
1934
                frameSpan->mBottomLeading;
1935
            }
1935
            }
1936
            else {
1936
            else {
1937
              pfd->mBounds.y = baselineY + parentDescent -
1937
              pfd->mBounds.y = baselineY + parentDescent -
1938
                pfd->mBounds.height - pfd->mMargin.bottom;
1938
                pfd->mBounds.height - pfd->mMargin.bottom;
 Lines 2090-2110   nsLineLayout::VerticalAlignFrames(PerSpa Link Here 
2090
      }
2090
      }
2091
    }
2091
    }
2092
    if (applyMinLH) {
2092
    if (applyMinLH) {
2093
      if ((psd->mX != psd->mLeftEdge) || preMode || foundLI) {
2093
      if ((psd->mX != psd->mLeftEdge) || preMode || foundLI) {
2094
#ifdef NOISY_VERTICAL_ALIGN
2094
#ifdef NOISY_VERTICAL_ALIGN
2095
        printf("  [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY);
2095
        printf("  [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY);
2096
#endif
2096
#endif
2097
        nscoord minimumLineHeight = mMinLineHeight;
2097
        nscoord minimumLineHeight = mMinLineHeight;
2098
        nscoord fontAscent, fontHeight;
2098
        nscoord fontAscent, fontDescent;
2099
        fm->GetMaxAscent(fontAscent);
2099
        fm->GetEmAscent(fontAscent);
2100
        fm->GetHeight(fontHeight);
2100
        fm->GetEmDescent(fontDescent);
2101
2101
2102
        nscoord leading = minimumLineHeight - fontHeight;
2102
        nscoord leading = minimumLineHeight - fontAscent - fontDescent;
2103
        nscoord yTop = -fontAscent - leading/2;
2103
        nscoord yTop = -fontAscent - leading/2;
2104
        nscoord yBottom = yTop + minimumLineHeight;
2104
        nscoord yBottom = yTop + minimumLineHeight;
2105
        if (yTop < minY) minY = yTop;
2105
        if (yTop < minY) minY = yTop;
2106
        if (yBottom > maxY) maxY = yBottom;
2106
        if (yBottom > maxY) maxY = yBottom;
2107
2107
2108
#ifdef NOISY_VERTICAL_ALIGN
2108
#ifdef NOISY_VERTICAL_ALIGN
2109
        printf(" new values: %d,%d\n", minY, maxY);
2109
        printf(" new values: %d,%d\n", minY, maxY);
2110
#endif
2110
#endif
(-)gfx/thebes/src/gfxFont.cpp (-5 / +10 lines)
Line     Link Here 
 Lines 282-299   gfxFont::Draw(gfxTextRun *aTextRun, PRUi Link Here 
282
                if (glyphData->IsMissing()) {
282
                if (glyphData->IsMissing()) {
283
                    if (!aDrawToPath) {
283
                    if (!aDrawToPath) {
284
                        gfxPoint pt(ToDeviceUnits(x, devUnitsPerAppUnit),
284
                        gfxPoint pt(ToDeviceUnits(x, devUnitsPerAppUnit),
285
                                    ToDeviceUnits(y, devUnitsPerAppUnit));
285
                                    ToDeviceUnits(y, devUnitsPerAppUnit));
286
                        gfxFloat advanceDevUnits = ToDeviceUnits(advance, devUnitsPerAppUnit);
286
                        gfxFloat advanceDevUnits = ToDeviceUnits(advance, devUnitsPerAppUnit);
287
                        if (isRTL) {
287
                        if (isRTL) {
288
                            pt.x -= advanceDevUnits;
288
                            pt.x -= advanceDevUnits;
289
                        }
289
                        }
290
                        gfxFloat height = GetMetrics().maxAscent;
290
                        const Metrics& fontMetrics = GetMetrics();
291
                        gfxRect glyphRect(pt.x, pt.y - height, advanceDevUnits, height);
291
                        gfxRect glyphRect(pt.x, pt.y - fontMetrics.emAscent,
292
                                          advanceDevUnits,
293
                                          fontMetrics.emAscent + fontMetrics.emDescent);
292
                        gfxFontMissingGlyphs::DrawMissingGlyph(aContext, glyphRect, details->mGlyphID);
294
                        gfxFontMissingGlyphs::DrawMissingGlyph(aContext, glyphRect, details->mGlyphID);
293
                    }
295
                    }
294
                } else {
296
                } else {
295
                    glyph = glyphs.AppendGlyph();
297
                    glyph = glyphs.AppendGlyph();
296
                    glyph->index = details->mGlyphID;
298
                    glyph->index = details->mGlyphID;
297
                    glyph->x = ToDeviceUnits(x + details->mXOffset, devUnitsPerAppUnit);
299
                    glyph->x = ToDeviceUnits(x + details->mXOffset, devUnitsPerAppUnit);
298
                    glyph->y = ToDeviceUnits(y + details->mYOffset, devUnitsPerAppUnit);
300
                    glyph->y = ToDeviceUnits(y + details->mYOffset, devUnitsPerAppUnit);
299
                    if (isRTL) {
301
                    if (isRTL) {
 Lines 373-392   gfxFont::Measure(gfxTextRun *aTextRun, Link Here 
373
                 PRBool aTightBoundingBox, gfxContext *aRefContext,
375
                 PRBool aTightBoundingBox, gfxContext *aRefContext,
374
                 Spacing *aSpacing)
376
                 Spacing *aSpacing)
375
{
377
{
376
    const PRUint32 appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit();
378
    const PRUint32 appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit();
377
    // Current position in appunits
379
    // Current position in appunits
378
    const gfxFont::Metrics& fontMetrics = GetMetrics();
380
    const gfxFont::Metrics& fontMetrics = GetMetrics();
379
381
380
    RunMetrics metrics;
382
    RunMetrics metrics;
381
    metrics.mAscent = fontMetrics.maxAscent*appUnitsPerDevUnit;
383
    metrics.mAscent = fontMetrics.emAscent * appUnitsPerDevUnit;
382
    metrics.mDescent = fontMetrics.maxDescent*appUnitsPerDevUnit;
384
    metrics.mDescent = fontMetrics.emDescent * appUnitsPerDevUnit;
383
    if (!aTightBoundingBox) {
385
    if (!aTightBoundingBox) {
384
        metrics.mBoundingBox = gfxRect(0, -metrics.mAscent, 0, metrics.mAscent + metrics.mDescent);
386
        gfxFloat y = -fontMetrics.maxAscent * appUnitsPerDevUnit;
387
        gfxFloat height =
388
            (fontMetrics.maxAscent + fontMetrics.maxDescent) * appUnitsPerDevUnit;
389
        metrics.mBoundingBox = gfxRect(0, y, 0, height);
385
    }
390
    }
386
    if (aStart == aEnd) {
391
    if (aStart == aEnd) {
387
      // exit now before we look at aSpacing[0], which is undefined
392
      // exit now before we look at aSpacing[0], which is undefined
388
      return metrics;
393
      return metrics;
389
    }
394
    }
390
395
391
    const gfxTextRun::CompressedGlyph *charGlyphs = aTextRun->GetCharacterGlyphs();
396
    const gfxTextRun::CompressedGlyph *charGlyphs = aTextRun->GetCharacterGlyphs();
392
    PRBool isRTL = aTextRun->IsRightToLeft();
397
    PRBool isRTL = aTextRun->IsRightToLeft();
(-)gfx/thebes/public/gfxFont.h (-1 / +1 lines)
Line     Link Here 
 Lines 446-462   public: Link Here 
446
        gfxFloat mAscent;  // always non-negative
446
        gfxFloat mAscent;  // always non-negative
447
        gfxFloat mDescent; // always non-negative
447
        gfxFloat mDescent; // always non-negative
448
        
448
        
449
        // Bounding box that is guaranteed to include everything drawn.
449
        // Bounding box that is guaranteed to include everything drawn.
450
        // If aTightBoundingBox was set to true when these metrics were
450
        // If aTightBoundingBox was set to true when these metrics were
451
        // generated, this will tightly wrap the glyphs, otherwise it is
451
        // generated, this will tightly wrap the glyphs, otherwise it is
452
        // "loose" and may be larger than the true bounding box.
452
        // "loose" and may be larger than the true bounding box.
453
        // Coordinates are relative to the baseline left origin, so typically
453
        // Coordinates are relative to the baseline left origin, so typically
454
        // mBoundingBox.y == -mAscent
454
        // mBoundingBox.y ~ -mAscent
455
        gfxRect  mBoundingBox;
455
        gfxRect  mBoundingBox;
456
    };
456
    };
457
457
458
    /**
458
    /**
459
     * Draw a series of glyphs to aContext. The direction of aTextRun must
459
     * Draw a series of glyphs to aContext. The direction of aTextRun must
460
     * be honoured.
460
     * be honoured.
461
     * @param aStart the first character to draw
461
     * @param aStart the first character to draw
462
     * @param aEnd draw characters up to here
462
     * @param aEnd draw characters up to here

Return to bug 402473