Qt 4.8
Functions | Variables
qprintengine_win.cpp File Reference
#include "qprinter_p.h"
#include "qprintengine_win_p.h"
#include <limits.h>
#include <private/qfont_p.h>
#include <private/qfontengine_p.h>
#include <private/qpainter_p.h>
#include <qbitmap.h>
#include <qdebug.h>
#include <qvector.h>
#include <qpicture.h>
#include <private/qpicture_p.h>

Go to the source code of this file.

Functions

static void draw_text_item_win (const QPointF &_pos, const QTextItemInt &ti, HDC hdc, bool convertToText, const QTransform &xform, const QPointF &topLeft)
 
static qreal inchesToMM (double in)
 
QPrinter::PaperSize mapDevmodePaperSize (int s)
 
static QPrinter::PaperSource mapDevmodePaperSource (int s)
 
static int mapPaperSizeDevmode (QPrinter::PaperSize s)
 
static int mapPaperSourceDevmode (QPrinter::PaperSource s)
 
static qreal mmToInches (double mm)
 
QPainterPath qt_regionToPath (const QRegion &region)
 

Variables

struct {
   QPrinter::PaperSize   qtSizeName
 
   int   winSizeName
 
dmMapping []
 
struct {
   QPrinter::PaperSource   qtSourceName
 
   int   winSourceName
 
sources []
 

Function Documentation

◆ draw_text_item_win()

static void draw_text_item_win ( const QPointF _pos,
const QTextItemInt ti,
HDC  hdc,
bool  convertToText,
const QTransform xform,
const QPointF topLeft 
)
static

Definition at line 1636 of file qprintengine_win.cpp.

Referenced by QWin32PrintEngine::drawTextItem().

1638 {
1639  QFontEngine *fe = ti.fontEngine;
1640  QPointF baseline_pos = xform.inverted().map(xform.map(pos) - topLeft);
1641 
1642  SetTextAlign(hdc, TA_BASELINE);
1643  SetBkMode(hdc, TRANSPARENT);
1644 
1645  bool has_kerning = ti.f && ti.f->kerning();
1646  QFontEngineWin *winfe = (fe->type() == QFontEngine::Win) ? static_cast<QFontEngineWin *>(fe) : 0;
1647 
1648  HFONT hfont;
1649  bool ttf = false;
1650 
1651  if (winfe) {
1652  hfont = winfe->hfont;
1653  ttf = winfe->ttf;
1654  } else {
1655  hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
1656  }
1657 
1658  HGDIOBJ old_font = SelectObject(hdc, hfont);
1659  unsigned int options = (ttf && !convertToText) ? ETO_GLYPH_INDEX : 0;
1660  wchar_t *convertedGlyphs = (wchar_t *)ti.chars;
1661  QGlyphLayout glyphs = ti.glyphs;
1662 
1663  bool fast = !has_kerning && !(ti.flags & QTextItem::RightToLeft);
1664  for (int i = 0; fast && i < glyphs.numGlyphs; i++) {
1665  if (glyphs.offsets[i].x != 0 || glyphs.offsets[i].y != 0 || glyphs.justifications[i].space_18d6 != 0
1666  || glyphs.attributes[i].dontPrint) {
1667  fast = false;
1668  break;
1669  }
1670  }
1671 
1672 #if !defined(Q_OS_WINCE)
1673  // Scale, rotate and translate here.
1674  XFORM win_xform;
1675  win_xform.eM11 = xform.m11();
1676  win_xform.eM12 = xform.m12();
1677  win_xform.eM21 = xform.m21();
1678  win_xform.eM22 = xform.m22();
1679  win_xform.eDx = xform.dx();
1680  win_xform.eDy = xform.dy();
1681 
1682  SetGraphicsMode(hdc, GM_ADVANCED);
1683  SetWorldTransform(hdc, &win_xform);
1684 #endif
1685 
1686  if (fast) {
1687  // fast path
1688  QVarLengthArray<wchar_t> g(glyphs.numGlyphs);
1689  for (int i = 0; i < glyphs.numGlyphs; ++i)
1690  g[i] = glyphs.glyphs[i];
1691  ExtTextOut(hdc,
1692  qRound(baseline_pos.x() + glyphs.offsets[0].x.toReal()),
1693  qRound(baseline_pos.y() + glyphs.offsets[0].y.toReal()),
1694  options, 0, convertToText ? convertedGlyphs : g.data(), glyphs.numGlyphs, 0);
1695  } else {
1697  QVarLengthArray<glyph_t> _glyphs;
1698 
1699  QTransform matrix = QTransform::fromTranslate(baseline_pos.x(), baseline_pos.y());
1700  ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags,
1701  _glyphs, positions);
1702  if (_glyphs.size() == 0) {
1703  SelectObject(hdc, old_font);
1704  return;
1705  }
1706 
1707  convertToText = convertToText && glyphs.numGlyphs == _glyphs.size();
1708  bool outputEntireItem = _glyphs.size() > 0;
1709 
1710  if (outputEntireItem) {
1711  options |= ETO_PDY;
1712  QVarLengthArray<INT> glyphDistances(_glyphs.size() * 2);
1713  QVarLengthArray<wchar_t> g(_glyphs.size());
1714  for (int i=0; i<_glyphs.size() - 1; ++i) {
1715  glyphDistances[i * 2] = qRound(positions[i + 1].x) - qRound(positions[i].x);
1716  glyphDistances[i * 2 + 1] = qRound(positions[i + 1].y) - qRound(positions[i].y);
1717  g[i] = _glyphs[i];
1718  }
1719  glyphDistances[(_glyphs.size() - 1) * 2] = 0;
1720  glyphDistances[(_glyphs.size() - 1) * 2 + 1] = 0;
1721  g[_glyphs.size() - 1] = _glyphs[_glyphs.size() - 1];
1722  ExtTextOut(hdc, qRound(positions[0].x), qRound(positions[0].y), options, 0,
1723  convertToText ? convertedGlyphs : g.data(), _glyphs.size(),
1724  glyphDistances.data());
1725  } else {
1726  int i = 0;
1727  while(i < _glyphs.size()) {
1728  wchar_t g = _glyphs[i];
1729 
1730  ExtTextOut(hdc, qRound(positions[i].x),
1731  qRound(positions[i].y), options, 0,
1732  convertToText ? convertedGlyphs + i : &g, 1, 0);
1733  ++i;
1734  }
1735  }
1736  }
1737 
1738 #if !defined(Q_OS_WINCE)
1739  win_xform.eM11 = win_xform.eM22 = 1.0;
1740  win_xform.eM12 = win_xform.eM21 = win_xform.eDx = win_xform.eDy = 0.0;
1741  SetWorldTransform(hdc, &win_xform);
1742 #endif
1743 
1744  SelectObject(hdc, old_font);
1745 }
QFontEngine * fontEngine
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
#define ETO_PDY
Definition: qt_windows.h:122
const QChar * chars
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
RenderFlags flags
#define ETO_GLYPH_INDEX
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
Definition: qfont.cpp:1416
#define ANSI_VAR_FONT
virtual Type type() const =0
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QGlyphLayout glyphs
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
const QFont * f
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
int size() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ inchesToMM()

static qreal inchesToMM ( double  in)
inlinestatic

Definition at line 400 of file qprintengine_win.cpp.

Referenced by QWin32PrintEnginePrivate::getPageMargins().

401 {
402  return in/0.039370147;
403 }

◆ mapDevmodePaperSize()

QPrinter::PaperSize mapDevmodePaperSize ( int  s)

Definition at line 110 of file qprintengine_win.cpp.

Referenced by QWin32PrintEngine::property(), and QWin32PrintEnginePrivate::updateCustomPaperSize().

111 {
112  int i = 0;
113  while ((dmMapping[i].winSizeName > 0) && (dmMapping[i].winSizeName != s))
114  i++;
115  return dmMapping[i].qtSizeName;
116 }
static const struct @249 dmMapping[]
int winSizeName

◆ mapDevmodePaperSource()

static QPrinter::PaperSource mapDevmodePaperSource ( int  s)
static

Definition at line 146 of file qprintengine_win.cpp.

Referenced by QWin32PrintEngine::property().

147 {
148  int i = 0;
149  while ((sources[i].winSourceName > 0) && (sources[i].winSourceName != s))
150  i++;
151  return sources[i].winSourceName ? sources[i].qtSourceName : (QPrinter::PaperSource) s;
152 }
int winSourceName
static const struct @250 sources[]
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103

◆ mapPaperSizeDevmode()

static int mapPaperSizeDevmode ( QPrinter::PaperSize  s)
static

Definition at line 118 of file qprintengine_win.cpp.

Referenced by QWin32PrintEngine::setProperty().

119 {
120  int i = 0;
121  while ((dmMapping[i].winSizeName > 0) && (dmMapping[i].qtSizeName != s))
122  i++;
123  return dmMapping[i].winSizeName;
124 }
QPrinter::PaperSize qtSizeName
static const struct @249 dmMapping[]
int winSizeName

◆ mapPaperSourceDevmode()

static int mapPaperSourceDevmode ( QPrinter::PaperSource  s)
static

Definition at line 154 of file qprintengine_win.cpp.

Referenced by QWin32PrintEngine::setProperty().

155 {
156  int i = 0;
157  while ((sources[i].qtSourceName >= 0) && (sources[i].qtSourceName != s))
158  i++;
159  return sources[i].winSourceName ? sources[i].winSourceName : s;
160 }
QPrinter::PaperSource qtSourceName
static const struct @250 sources[]

◆ mmToInches()

static qreal mmToInches ( double  mm)
inlinestatic

◆ qt_regionToPath()

QPainterPath qt_regionToPath ( const QRegion region)

Definition at line 1160 of file qregion.cpp.

Referenced by QWin32PrintEngine::updateClipPath(), and QWin32PrintEngine::updateState().

1161 {
1162  QPainterPath result;
1163  if (region.rectCount() == 1) {
1164  result.addRect(region.boundingRect());
1165  return result;
1166  }
1167 
1168  const QVector<QRect> rects = region.rects();
1169 
1170  QVarLengthArray<Segment> segments;
1171  segments.resize(4 * rects.size());
1172 
1173  const QRect *rect = rects.constData();
1174  const QRect *end = rect + rects.size();
1175 
1176  int lastRowSegmentCount = 0;
1177  Segment *lastRowSegments = 0;
1178 
1179  int lastSegment = 0;
1180  int lastY = 0;
1181  while (rect != end) {
1182  const int y = rect[0].y();
1183  int count = 0;
1184  while (&rect[count] != end && rect[count].y() == y)
1185  ++count;
1186 
1187  for (int i = 0; i < count; ++i) {
1188  int offset = lastSegment + i;
1189  segments[offset] = Segment(rect[i].topLeft());
1190  segments[offset += count] = Segment(rect[i].topRight() + QPoint(1, 0));
1191  segments[offset += count] = Segment(rect[i].bottomRight() + QPoint(1, 1));
1192  segments[offset += count] = Segment(rect[i].bottomLeft() + QPoint(0, 1));
1193 
1194  offset = lastSegment + i;
1195  for (int j = 0; j < 4; ++j)
1196  segments[offset + j * count].connect(segments[offset + ((j + 1) % 4) * count]);
1197  }
1198 
1199  if (lastRowSegments && lastY == y)
1200  mergeSegments(lastRowSegments, lastRowSegmentCount, &segments[lastSegment], count);
1201 
1202  lastRowSegments = &segments[lastSegment + 2 * count];
1203  lastRowSegmentCount = count;
1204  lastSegment += 4 * count;
1205  lastY = y + rect[0].height();
1206  rect += count;
1207  }
1208 
1209  for (int i = 0; i < lastSegment; ++i) {
1210  Segment *segment = &segments[i];
1211  if (!segment->added)
1212  addSegmentsToPath(segment, result);
1213  }
1214 
1215  return result;
1216 }
void resize(int size)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

Variable Documentation

◆ dmMapping

const { ... } dmMapping[]

◆ qtSizeName

QPrinter::PaperSize qtSizeName

Definition at line 70 of file qprintengine_win.cpp.

Referenced by mapPaperSizeDevmode().

◆ qtSourceName

QPrinter::PaperSource qtSourceName

Definition at line 128 of file qprintengine_win.cpp.

Referenced by mapPaperSourceDevmode().

◆ sources

const { ... } sources[]
Initial value:
= {
{ DMBIN_ONLYONE, QPrinter::OnlyOne },
{ DMBIN_LOWER, QPrinter::Lower },
{ DMBIN_MIDDLE, QPrinter::Middle },
{ DMBIN_MANUAL, QPrinter::Manual },
{ DMBIN_ENVELOPE, QPrinter::Envelope },
{ DMBIN_ENVMANUAL, QPrinter::EnvelopeManual },
{ DMBIN_AUTO, QPrinter::Auto },
{ DMBIN_TRACTOR, QPrinter::Tractor },
{ DMBIN_SMALLFMT, QPrinter::SmallFormat },
{ DMBIN_LARGEFMT, QPrinter::LargeFormat },
{ DMBIN_LARGECAPACITY, QPrinter::LargeCapacity },
{ DMBIN_CASSETTE, QPrinter::Cassette },
{ DMBIN_FORMSOURCE, QPrinter::FormSource },
}
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103

Referenced by mapDevmodePaperSource(), and mapPaperSourceDevmode().

◆ winSizeName

int winSizeName

Definition at line 69 of file qprintengine_win.cpp.

Referenced by mapDevmodePaperSize(), and mapPaperSizeDevmode().

◆ winSourceName

int winSourceName

Definition at line 127 of file qprintengine_win.cpp.

Referenced by mapDevmodePaperSource().