1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
* Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "AffineTransform.h"
#include "GlyphBuffer.h"
#include "GraphicsContext.h"
#include "SimpleFontData.h"
#include <wtf/MathExtras.h>
#include <wx/defs.h>
#if 1 // !wxUSE_CAIRO
#include <wx/dcclient.h>
#include <wx/dcgraph.h>
#include <wx/gdicmn.h>
#include <vector>
using namespace std;
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
const double RAD2DEG = 180.0 / piDouble;
//-----------------------------------------------------------------------------
// Local functions
//-----------------------------------------------------------------------------
static inline double dmin(double a, double b) { return a < b ? a : b; }
static inline double dmax(double a, double b) { return a > b ? a : b; }
static inline double DegToRad(double deg) { return deg2rad(deg); }
static inline double RadToDeg(double rad) { return rad2deg(rad); }
#include "wx/msw/private.h"
// TODO remove this dependency (gdiplus needs the macros)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#include "gdiplus.h"
#if wxUSE_CAIRO
#include <cairo.h>
#include <cairo-win32.h>
#endif
namespace WebCore {
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
#if USE(WXGC)
wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());
#else
wxDC* dc = graphicsContext->platformContext();
#endif
// get the native HDC handle to draw using native APIs
HDC hdc = 0;
float y = point.y() - font->fontMetrics().ascent();
float x = point.x();
#if USE(WXGC)
wxGraphicsContext* gc = dc->GetGraphicsContext();
#if wxUSE_CAIRO
cairo_t* context = (cairo_t*)gc->GetNativeContext();
if (context) {
cairo_surface_t* surface = cairo_get_target(context);
hdc = cairo_win32_surface_get_dc(surface);
}
#else
// when going from GdiPlus -> Gdi, any GdiPlus transformations are lost
// so we need to alter the coordinates to reflect their transformed point.
double xtrans = 0;
double ytrans = 0;
gc->GetTransform().TransformPoint(&xtrans, &ytrans);
Gdiplus::Graphics* g;
if (gc) {
g = (Gdiplus::Graphics*)gc->GetNativeContext();
hdc = g->GetHDC();
}
x += (int)xtrans;
y += (int)ytrans;
#endif // wxUSE_CAIRO
#else
hdc = static_cast<HDC>(dc->GetHDC());
#endif
// if the context has been scaled, we must manually re-apply that scale
// to the HDC.
FloatSize scale = graphicsContext->currentScale();
if (scale != FloatSize(1.0, 1.0)) {
SetGraphicsMode(hdc, GM_ADVANCED);
XFORM xForm;
xForm.eM11 = scale.width();
xForm.eM12 = 0.0;
xForm.eM21 = 0.0;
xForm.eM22 = scale.height();
xForm.eDx = 0.0;
xForm.eDy = 0.0;
SetWorldTransform(hdc, &xForm);
}
// ExtTextOut wants the offsets as an array of ints, so extract them
// from the glyph buffer
const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
const GlyphBufferAdvance* advances = glyphBuffer.advances(from);
int* spacing = new int[numGlyphs - from];
for (unsigned i = 0; i < numGlyphs; ++i)
spacing[i] = advances[i].width();
wxFont* wxfont = font->getWxFont();
if (wxfont && wxfont->IsOk())
::SelectObject(hdc, GetHfontOf(*wxfont));
if (color.Ok())
::SetTextColor(hdc, color.GetPixel());
// do not draw background behind characters
::SetBkMode(hdc, TRANSPARENT);
// draw text with optional character widths array
wxString string = wxString((wxChar*)(&glyphs[from]), numGlyphs);
::ExtTextOut(hdc, x, y, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphs), numGlyphs, spacing);
::SetBkMode(hdc, TRANSPARENT);
#if USE(WXGC) && !wxUSE_CAIRO
g->ReleaseHDC(hdc);
#endif
delete [] spacing;
}
}
#endif
|