33 #include <mrpt/config.h>
43 : m_scale(scaleFactor), m_targetFile(targetFileName)
47 CreateEnhMetaFileA(
nullptr, targetFileName.c_str(),
nullptr,
nullptr);
72 DeleteEnhMetaFile(CloseEnhMetaFile((HDC)
m_hdc.
get()));
89 LPBITMAPINFO pBmpInfo =
90 (LPBITMAPINFO)
new unsigned char[
sizeof(BITMAPINFOHEADER) +
91 (256 *
sizeof(RGBQUAD))];
95 unsigned int imgWidth = (
unsigned int)
img.getWidth();
96 unsigned int imgHeight = (
unsigned int)
img.getHeight();
98 pBmpInfo->bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
99 pBmpInfo->bmiHeader.biWidth = imgWidth;
100 pBmpInfo->bmiHeader.biHeight = imgHeight;
101 pBmpInfo->bmiHeader.biPlanes = 1;
103 pBmpInfo->bmiHeader.biBitCount = 8;
104 pBmpInfo->bmiHeader.biCompression = BI_RGB;
105 pBmpInfo->bmiHeader.biSizeImage = 0;
106 pBmpInfo->bmiHeader.biXPelsPerMeter =
107 pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
108 pBmpInfo->bmiHeader.biClrUsed = 0;
109 pBmpInfo->bmiHeader.biClrImportant = 0;
112 for (
unsigned char i = 0; i < 255; i++)
114 pBmpInfo->bmiColors[i].rgbRed = i;
115 pBmpInfo->bmiColors[i].rgbGreen = i;
116 pBmpInfo->bmiColors[i].rgbBlue = i;
117 pBmpInfo->bmiColors[i].rgbReserved = 0;
121 unsigned int lineBytes = imgWidth;
122 if (lineBytes % 2) lineBytes++;
123 if (lineBytes % 4) lineBytes += 2;
125 BYTE* ptrBits =
new BYTE[lineBytes * imgHeight];
127 for (
unsigned int py = 0; py < imgHeight; py++)
128 for (
unsigned int px = 0; px < imgWidth; px++)
129 ptrBits[(py * lineBytes + px) + 0] = *
img(px, py);
131 HBITMAP hBitmap = CreateDIBitmap(
132 (HDC)
m_hdc.
get(), &pBmpInfo->bmiHeader, CBM_INIT, ptrBits, pBmpInfo,
138 GetObject(hBitmap,
sizeof(bm), &bm);
140 HDC hdcMem = CreateCompatibleDC((HDC)
m_hdc.
get());
141 HBITMAP hbmT = (HBITMAP)SelectObject(hdcMem, hBitmap);
145 (
int)(
m_scale * imgHeight), hdcMem, 0, 0, SRCCOPY);
147 SelectObject(hdcMem, hbmT);
152 DeleteObject(hBitmap);
178 HPEN hPen = CreatePen(penStyle,
width, (
unsigned int)
color);
180 HPEN hOldPen = (HPEN)SelectObject((HDC)
m_hdc.
get(), hPen);
182 MoveToEx((HDC)
m_hdc.
get(), x0, y0,
nullptr);
185 SelectObject((HDC)
m_hdc.
get(), hOldPen);
202 ::SetBkMode((HDC)
m_hdc.
get(), TRANSPARENT);
205 ::TextOutA((HDC)
m_hdc.
get(), x0, y0, str.c_str(), (
int)str.size());
215 const std::string& fontName,
int fontSize,
bool bold,
bool italic)
218 HFONT hFont, oldFont;
221 lpf.lfHeight = fontSize;
223 lpf.lfEscapement = 0;
224 lpf.lfOrientation = 0;
225 lpf.lfWeight = bold ? 700 : 400;
226 lpf.lfItalic = italic ? 1 : 0;
229 lpf.lfCharSet = DEFAULT_CHARSET;
230 lpf.lfOutPrecision = OUT_DEFAULT_PRECIS;
231 lpf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
232 lpf.lfQuality = DEFAULT_QUALITY;
233 lpf.lfPitchAndFamily = DEFAULT_PITCH;
234 os::strcpy(lpf.lfFaceName, LF_FACESIZE, fontName.c_str());
236 hFont = ::CreateFontIndirectA(&lpf);
238 oldFont = (HFONT)::SelectObject((HDC)
m_hdc.
get(), hFont);
240 if (oldFont) ::DeleteObject(oldFont);