non-kerned-drawing.cpp [plain text]
#include "config.h"
#include "AffineTransform.h"
#include "GlyphBuffer.h"
#include "GraphicsContext.h"
#include "SimpleFontData.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;
const double RAD2DEG = 180.0 / M_PI;
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 (deg * M_PI) / 180.0; }
static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; }
#include "wx/msw/private.h"
#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
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
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
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);
}
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());
::SetBkMode(hdc, TRANSPARENT);
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