From 5e5adb0495d0ec0de76cc12480871d9eb885142c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 29 Jun 2011 14:34:58 -0700 Subject: [PATCH] Bug 662038, part 0: Add gfxContext::CurrentDash(). r=jrmuizel --- gfx/thebes/gfxContext.cpp | 23 ++++++++++++++++++++++- gfx/thebes/gfxContext.h | 8 +++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gfx/thebes/gfxContext.cpp b/gfx/thebes/gfxContext.cpp index a2f3e68afbf..e165dbfcea2 100644 --- a/gfx/thebes/gfxContext.cpp +++ b/gfx/thebes/gfxContext.cpp @@ -545,7 +545,28 @@ gfxContext::SetDash(gfxFloat *dashes, int ndash, gfxFloat offset) { cairo_set_dash(mCairo, dashes, ndash, offset); } -//void getDash() const; + +bool +gfxContext::CurrentDash(FallibleTArray& dashes, gfxFloat* offset) const +{ + int count = cairo_get_dash_count(mCairo); + if (count <= 0 || !dashes.SetLength(count)) { + return false; + } + cairo_get_dash(mCairo, dashes.Elements(), offset); + return true; +} + +gfxFloat +gfxContext::CurrentDashOffset() const +{ + if (cairo_get_dash_count(mCairo) <= 0) { + return 0.0; + } + gfxFloat offset; + cairo_get_dash(mCairo, NULL, &offset); + return offset; +} void gfxContext::SetLineWidth(gfxFloat width) diff --git a/gfx/thebes/gfxContext.h b/gfx/thebes/gfxContext.h index 9f6a7a97b8c..eca64350d1c 100644 --- a/gfx/thebes/gfxContext.h +++ b/gfx/thebes/gfxContext.h @@ -51,6 +51,7 @@ #include "nsISupportsImpl.h" typedef struct _cairo cairo_t; +template class FallibleTArray; /** * This is the main class for doing actual drawing. It is initialized using @@ -465,7 +466,12 @@ public: void SetDash(gfxLineType ltype); void SetDash(gfxFloat *dashes, int ndash, gfxFloat offset); - //void getDash() const; + // Return true if dashing is set, false if it's not enabled or the + // context is in an error state. |offset| can be NULL to mean + // "don't care". + bool CurrentDash(FallibleTArray& dashes, gfxFloat* offset) const; + // Returns 0.0 if dashing isn't enabled. + gfxFloat CurrentDashOffset() const; /** * Sets the line width that's used for line drawing.