Skip to content

Commit

Permalink
Backout changesets fad675db4598 and 618d8f44d9e2 (bug 1090168 pt 1 an…
Browse files Browse the repository at this point in the history
…d 2) for Nightly crashiness. a=backout
  • Loading branch information
jfkthame committed Nov 15, 2014
1 parent f9a2419 commit 0e4e955
Showing 1 changed file with 19 additions and 52 deletions.
71 changes: 19 additions & 52 deletions dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
@@ -1469,25 +1469,6 @@ CanvasRenderingContext2D::ClearTarget()
state->colorStyles[Style::FILL] = NS_RGB(0,0,0);
state->colorStyles[Style::STROKE] = NS_RGB(0,0,0);
state->shadowColor = NS_RGBA(0,0,0,0);

// For vertical writing-mode, unless text-orientation is sideways,
// we'll modify the initial value of textBaseline to 'middle'.
nsRefPtr<nsStyleContext> canvasStyle;
if (mCanvasElement && mCanvasElement->IsInDoc()) {
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
if (presShell) {
canvasStyle =
nsComputedDOMStyle::GetStyleContextForElement(mCanvasElement,
nullptr,
presShell);
if (canvasStyle) {
WritingMode wm(canvasStyle);
if (wm.IsVertical() && !wm.IsSideways()) {
state->textBaseline = TextBaseline::MIDDLE;
}
}
}
}
}

NS_IMETHODIMP
@@ -3284,7 +3265,6 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcess
gfxPoint point = mPt;
bool rtl = mTextRun->IsRightToLeft();
bool verticalRun = mTextRun->IsVertical();
bool centerBaseline = mTextRun->UseCenterBaseline();

gfxFloat& inlineCoord = verticalRun ? point.y : point.x;
inlineCoord += xOffset;
@@ -3353,27 +3333,20 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcess
if (runs[c].mOrientation ==
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT) {
sidewaysRestore.Init(mCtx->mTarget);
// TODO: The baseline adjustment here is kinda ad-hoc; eventually
// perhaps we should check for horizontal and vertical baseline data
// in the font, and adjust accordingly.
// (The same will be true for HTML text layout.)
const gfxFont::Metrics& metrics = mTextRun->GetFontGroup()->
GetFirstValidFont()->GetMetrics(gfxFont::eHorizontal);

gfx::Matrix mat = mCtx->mTarget->GetTransform().Copy().
mCtx->mTarget->SetTransform(mCtx->mTarget->GetTransform().Copy().
PreTranslate(baselineOrigin). // translate origin for rotation
PreRotate(gfx::Float(M_PI / 2.0)). // turn 90deg clockwise
PreTranslate(-baselineOrigin); // undo the translation

if (centerBaseline) {
// TODO: The baseline adjustment here is kinda ad hoc; eventually
// perhaps we should check for horizontal and vertical baseline data
// in the font, and adjust accordingly.
// (The same will be true for HTML text layout.)
float offset = (metrics.emAscent - metrics.emDescent) / 2;
mat = mat.PreTranslate(Point(0, offset));
// offset the (alphabetic) baseline of the
PreTranslate(-baselineOrigin). // undo the translation
PreTranslate(Point(0, (metrics.emAscent - metrics.emDescent) / 2)));
// and offset the (alphabetic) baseline of the
// horizontally-shaped text from the (centered)
// default baseline used for vertical
}

mCtx->mTarget->SetTransform(mat);
}

RefPtr<GlyphRenderingOptions> renderingOptions = font->GetGlyphRenderingOptions();
@@ -3665,45 +3638,39 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,

processor.mPt.x -= anchorX * totalWidth;

// offset pt.y (or pt.x, for vertical text) based on text baseline
// offset pt.y based on text baseline
processor.mFontgrp->UpdateUserFonts(); // ensure user font generation is current
const gfxFont::Metrics& fontMetrics =
processor.mFontgrp->GetFirstValidFont()->GetMetrics(gfxFont::eHorizontal);
processor.mFontgrp->GetFirstValidFont()->GetMetrics(
((processor.mTextRunFlags & gfxTextRunFactory::TEXT_ORIENT_MASK) ==
gfxTextRunFactory::TEXT_ORIENT_HORIZONTAL)
? gfxFont::eHorizontal : gfxFont::eVertical);

gfxFloat baselineAnchor;
gfxFloat anchorY;

switch (state.textBaseline)
{
case TextBaseline::HANGING:
// fall through; best we can do with the information available
case TextBaseline::TOP:
baselineAnchor = fontMetrics.emAscent;
anchorY = fontMetrics.emAscent;
break;
case TextBaseline::MIDDLE:
baselineAnchor = (fontMetrics.emAscent - fontMetrics.emDescent) * .5f;
anchorY = (fontMetrics.emAscent - fontMetrics.emDescent) * .5f;
break;
case TextBaseline::IDEOGRAPHIC:
// fall through; best we can do with the information available
case TextBaseline::ALPHABETIC:
baselineAnchor = 0;
anchorY = 0;
break;
case TextBaseline::BOTTOM:
baselineAnchor = -fontMetrics.emDescent;
anchorY = -fontMetrics.emDescent;
break;
default:
MOZ_CRASH("unexpected TextBaseline");
}

if (processor.mTextRun->IsVertical()) {
if (processor.mTextRun->UseCenterBaseline()) {
// Adjust to account for mTextRun being shaped using center baseline
// rather than alphabetic.
baselineAnchor -= (fontMetrics.emAscent - fontMetrics.emDescent) * .5f;
}
processor.mPt.x -= baselineAnchor;
} else {
processor.mPt.y += baselineAnchor;
}
processor.mPt.y += anchorY;

// correct bounding box to get it to be the correct size/position
processor.mBoundingBox.width = totalWidth;

0 comments on commit 0e4e955

Please sign in to comment.