2 * Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "AffineTransform.h"
29 #include "GlyphBuffer.h"
30 #include "GraphicsContext.h"
31 #include "SimpleFontData.h"
37 #include <wx/dcclient.h>
38 #include <wx/dcgraph.h>
39 #include <wx/gdicmn.h>
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 const double RAD2DEG = 180.0 / M_PI;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static inline double dmin(double a, double b) { return a < b ? a : b; }
55 static inline double dmax(double a, double b) { return a > b ? a : b; }
57 static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
58 static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; }
60 #include "wx/msw/private.h"
62 // TODO remove this dependency (gdiplus needs the macros)
65 #define max(a,b) (((a) > (b)) ? (a) : (b))
69 #define min(a,b) (((a) < (b)) ? (a) : (b))
76 #include <cairo-win32.h>
81 void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
86 wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());
88 wxDC* dc = graphicsContext->platformContext();
91 // get the native HDC handle to draw using native APIs
93 float y = point.y() - font->fontMetrics().ascent();
99 wxGraphicsContext* gc = dc->GetGraphicsContext();
101 cairo_t* context = (cairo_t*)gc->GetNativeContext();
103 cairo_surface_t* surface = cairo_get_target(context);
104 hdc = cairo_win32_surface_get_dc(surface);
107 // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost
108 // so we need to alter the coordinates to reflect their transformed point.
112 gc->GetTransform().TransformPoint(&xtrans, &ytrans);
113 Gdiplus::Graphics* g;
115 g = (Gdiplus::Graphics*)gc->GetNativeContext();
120 #endif // wxUSE_CAIRO
122 hdc = static_cast<HDC>(dc->GetHDC());
125 // if the context has been scaled, we must manually re-apply that scale
127 FloatSize scale = graphicsContext->currentScale();
128 if (scale != FloatSize(1.0, 1.0)) {
129 SetGraphicsMode(hdc, GM_ADVANCED);
131 xForm.eM11 = scale.width();
134 xForm.eM22 = scale.height();
137 SetWorldTransform(hdc, &xForm);
139 // ExtTextOut wants the offsets as an array of ints, so extract them
140 // from the glyph buffer
141 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
142 const GlyphBufferAdvance* advances = glyphBuffer.advances(from);
144 int* spacing = new int[numGlyphs - from];
145 for (unsigned i = 0; i < numGlyphs; ++i)
146 spacing[i] = advances[i].width();
148 wxFont* wxfont = font->getWxFont();
149 if (wxfont && wxfont->IsOk())
150 ::SelectObject(hdc, GetHfontOf(*wxfont));
153 ::SetTextColor(hdc, color.GetPixel());
155 // do not draw background behind characters
156 ::SetBkMode(hdc, TRANSPARENT);
158 // draw text with optional character widths array
159 wxString string = wxString((wxChar*)(&glyphs[from]), numGlyphs);
160 ::ExtTextOut(hdc, x, y, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphs), numGlyphs, spacing);
162 ::SetBkMode(hdc, TRANSPARENT);
164 #if USE(WXGC) && !wxUSE_CAIRO