diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-04 16:21:25 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-04 16:21:25 +0000 |
commit | d1f72ed6e0c95e8437de2d914a7a97183d4aa443 (patch) | |
tree | 14c2ccbd157ff6e373df274b63f9a02bce174721 /chrome/common/gfx | |
parent | 78117b9c3b21847aee5373b3d936bb7213216ce6 (diff) | |
download | chromium_src-d1f72ed6e0c95e8437de2d914a7a97183d4aa443.zip chromium_src-d1f72ed6e0c95e8437de2d914a7a97183d4aa443.tar.gz chromium_src-d1f72ed6e0c95e8437de2d914a7a97183d4aa443.tar.bz2 |
Fixes two Linux canvas related bugs.
. The platform paint was allocating at a size bigger than necessary.
. ChromeCanvas::DrawStringInt was not taking into account the matrix on
the canvas, which means the text could be drawn at the wrong
location.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/99279
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/gfx')
-rw-r--r-- | chrome/common/gfx/chrome_canvas.h | 11 | ||||
-rw-r--r-- | chrome/common/gfx/chrome_canvas_linux.cc | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/chrome/common/gfx/chrome_canvas.h b/chrome/common/gfx/chrome_canvas.h index a16f9da..72db8a5 100644 --- a/chrome/common/gfx/chrome_canvas.h +++ b/chrome/common/gfx/chrome_canvas.h @@ -19,6 +19,10 @@ namespace gfx { class Rect; } +#if defined(OS_LINUX) +typedef struct _cairo cairo_t; +#endif + // ChromeCanvas is the SkCanvas used by Views for all painting. It // provides a handful of methods for the common operations used throughout // Views. With few exceptions, you should NOT create a ChromeCanvas directly, @@ -179,6 +183,13 @@ class ChromeCanvas : public skia::PlatformCanvas { // Extracts a bitmap from the contents of this canvas. SkBitmap ExtractBitmap(); +#if defined(OS_LINUX) + // Applies current matrix on the canvas to the cairo context. This should be + // invoked anytime you plan on drawing directly to the cairo context. Be + // sure and set the matrix back to the identity when done. + void ApplySkiaMatrixToCairoContext(cairo_t* cr); +#endif + // Compute the size required to draw some text with the provided font. // Attempts to fit the text with the provided width and height. Increases // height and then width as needed to make the text fit. This method diff --git a/chrome/common/gfx/chrome_canvas_linux.cc b/chrome/common/gfx/chrome_canvas_linux.cc index 93a32f7..5f8b430 100644 --- a/chrome/common/gfx/chrome_canvas_linux.cc +++ b/chrome/common/gfx/chrome_canvas_linux.cc @@ -58,6 +58,18 @@ void ChromeCanvas::SizeStringInt(const std::wstring& text, NOTIMPLEMENTED(); } +void ChromeCanvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) { + const SkMatrix& skia_matrix = getTotalMatrix(); + cairo_matrix_t cairo_matrix; + cairo_matrix_init(&cairo_matrix, + SkScalarToFloat(skia_matrix.getScaleX()), + SkScalarToFloat(skia_matrix.getSkewY()), + SkScalarToFloat(skia_matrix.getSkewX()), + SkScalarToFloat(skia_matrix.getScaleY()), + SkScalarToFloat(skia_matrix.getTranslateX()), + SkScalarToFloat(skia_matrix.getTranslateY())); + cairo_set_matrix(cr, &cairo_matrix); +} void ChromeCanvas::DrawStringInt(const std::wstring& text, const ChromeFont& font, @@ -65,6 +77,10 @@ void ChromeCanvas::DrawStringInt(const std::wstring& text, int h, int flags) { cairo_surface_t* surface = beginPlatformPaint(); cairo_t* cr = cairo_create(surface); + // We're going to draw onto the surface directly. This circumvents the matrix + // installed by Skia. Apply the matrix from skia to cairo so they align and + // we draw at the right place. + ApplySkiaMatrixToCairoContext(cr); PangoLayout* layout = pango_cairo_create_layout(cr); cairo_set_source_rgb(cr, |