Bug 1166147 - Part1: Ignore writing mode while printing header and footer r?dholbert
MozReview-Commit-ID: Kesy6LG2KNe
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -5728,31 +5728,38 @@ nsLayoutUtils::AppUnitBoundsOfString(con
totalMetrics += metrics;
aLength -= len;
aString += len;
}
return totalMetrics;
}
void
-nsLayoutUtils::DrawString(const nsIFrame* aFrame,
- nsFontMetrics& aFontMetrics,
- nsRenderingContext* aContext,
- const char16_t* aString,
- int32_t aLength,
- nsPoint aPoint,
- nsStyleContext* aStyleContext)
+nsLayoutUtils::DrawString(const nsIFrame* aFrame,
+ nsFontMetrics& aFontMetrics,
+ nsRenderingContext* aContext,
+ const char16_t* aString,
+ int32_t aLength,
+ nsPoint aPoint,
+ nsStyleContext* aStyleContext,
+ DrawStringFlags aFlags)
{
nsresult rv = NS_ERROR_FAILURE;
// If caller didn't pass a style context, use the frame's.
if (!aStyleContext) {
aStyleContext = aFrame->StyleContext();
}
- aFontMetrics.SetVertical(WritingMode(aStyleContext).IsVertical());
+
+ if (aFlags & DrawStringFlags::eForceHorizontal) {
+ aFontMetrics.SetVertical(false);
+ } else {
+ aFontMetrics.SetVertical(WritingMode(aStyleContext).IsVertical());
+ }
+
aFontMetrics.SetTextOrientation(
aStyleContext->StyleVisibility()->mTextOrientation);
nsPresContext* presContext = aFrame->PresContext();
if (presContext->BidiEnabled()) {
nsBidiLevel level =
nsBidiPresUtils::BidiLevelFromStyle(aStyleContext);
rv = nsBidiPresUtils::RenderText(aString, aLength, level,
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -112,16 +112,23 @@ struct DisplayPortMarginsPropertyData {
} // namespace mozilla
// For GetDisplayPort
enum class RelativeTo {
ScrollPort,
ScrollFrame
};
+// Flags to customize the behavior of nsLayoutUtils::DrawString.
+enum class DrawStringFlags {
+ eDefault = 0x0,
+ eForceHorizontal = 0x1 // Forces the text to be drawn horizontally.
+};
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DrawStringFlags)
+
/**
* nsLayoutUtils is a namespace class used for various helper
* functions that are useful in multiple places in layout. The goal
* is not to define multiple copies of the same static helper.
*/
class nsLayoutUtils
{
typedef mozilla::dom::DOMRectList DOMRectList;
@@ -1601,23 +1608,24 @@ public:
DrawTarget* aDrawTarget,
nscoord aWidth);
static nsBoundingMetrics AppUnitBoundsOfString(const char16_t* aString,
uint32_t aLength,
nsFontMetrics& aFontMetrics,
DrawTarget* aDrawTarget);
- static void DrawString(const nsIFrame* aFrame,
- nsFontMetrics& aFontMetrics,
- nsRenderingContext* aContext,
- const char16_t* aString,
- int32_t aLength,
- nsPoint aPoint,
- nsStyleContext* aStyleContext = nullptr);
+ static void DrawString(const nsIFrame* aFrame,
+ nsFontMetrics& aFontMetrics,
+ nsRenderingContext* aContext,
+ const char16_t* aString,
+ int32_t aLength,
+ nsPoint aPoint,
+ nsStyleContext* aStyleContext = nullptr,
+ DrawStringFlags aFlags = DrawStringFlags::eDefault);
/**
* Supports only LTR or RTL. Bidi (mixed direction) is not supported.
*/
static void DrawUniDirString(const char16_t* aString,
uint32_t aLength,
nsPoint aPoint,
nsFontMetrics& aFontMetrics,
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -167,17 +167,17 @@ nsPageFrame::Reflow(nsPresContext*
PR_PL(("[%d,%d]\n", aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()));
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
}
nsIAtom*
nsPageFrame::GetType() const
{
- return nsGkAtoms::pageFrame;
+ return nsGkAtoms::pageFrame;
}
#ifdef DEBUG_FRAME_DUMP
nsresult
nsPageFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("Page"), aResult);
}
@@ -388,17 +388,19 @@ nsPageFrame::DrawHeaderFooter(nsRenderin
// set up new clip and draw the text
gfx->Save();
gfx->Clip(NSRectToSnappedRect(aRect, PresContext()->AppUnitsPerDevPixel(),
*drawTarget));
gfx->SetColor(Color(0.f, 0.f, 0.f));
nsLayoutUtils::DrawString(this, aFontMetrics, &aRenderingContext,
str.get(), str.Length(),
- nsPoint(x, y + aAscent));
+ nsPoint(x, y + aAscent),
+ nullptr,
+ DrawStringFlags::eForceHorizontal);
gfx->Restore();
}
}
/**
* Remove all leaf display items that are not for descendants of
* aBuilder->GetReferenceFrame() from aList.
* @param aPage the page we're constructing the display list for
@@ -730,17 +732,17 @@ nsPageBreakFrame::Reflow(nsPresContext*
// DidReflow will always get called before the next Reflow() call.
mHaveReflowed = true;
aStatus = NS_FRAME_COMPLETE;
}
nsIAtom*
nsPageBreakFrame::GetType() const
{
- return nsGkAtoms::pageBreakFrame;
+ return nsGkAtoms::pageBreakFrame;
}
#ifdef DEBUG_FRAME_DUMP
nsresult
nsPageBreakFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("PageBreak"), aResult);
}