Text::Text(WCHAR* TEXT, int X, int Y) { HFONT hfont; hfont = ::CreateFontIndirect(&this->font); SelectObject(this->hdc, hfont); TextOutW(this->hdc, X, Y, TEXT, wcslen(TEXT)); }
/* Updates cursor position */ static void text_update_text(TW *tw, int count) { HDC hdc; int xpos, ypos; xpos = tw->CursorPos.x*tw->CharSize.x - tw->ScrollPos.x; ypos = tw->CursorPos.y*tw->CharSize.y - tw->ScrollPos.y; hdc = GetDC(tw->hwnd); SelectFont(hdc, tw->hfont); #ifdef WINDOWS_NO_UNICODE TextOut(hdc,xpos,ypos, (LPSTR)(tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x), count); #else TextOutW(hdc,xpos,ypos, (LPCWSTR)(tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x + tw->CursorPos.x), count); #endif (void)ReleaseDC(tw->hwnd,hdc); tw->CursorPos.x += count; if (tw->CursorPos.x >= tw->ScreenSize.x) text_new_line(tw); }
void W32ColorComboBox::drawItemCallback(DRAWITEMSTRUCT &di) { RECT rectangle; rectangle.top = di.rcItem.top + 1; rectangle.bottom = di.rcItem.bottom - 2; rectangle.left = di.rcItem.left + 2; rectangle.right = rectangle.left + 3 * (myPixelHeight - 4) / 2; MoveToEx(di.hDC, rectangle.left, rectangle.top, 0); LineTo(di.hDC, rectangle.left, rectangle.bottom); LineTo(di.hDC, rectangle.right, rectangle.bottom); LineTo(di.hDC, rectangle.right, rectangle.top); LineTo(di.hDC, rectangle.left, rectangle.top); ++rectangle.top; ++rectangle.left; ZLColor color = this->color(di.itemID); HBRUSH brush = CreateSolidBrush(RGB(color.Red, color.Green, color.Blue)); FillRect(di.hDC, &rectangle, brush); DeleteObject(brush); TEXTMETRIC tm; const ZLUnicodeUtil::Ucs2String &txt = text(di.itemID); GetTextMetrics(di.hDC, &tm); if (!txt.empty()) { TextOutW(di.hDC, rectangle.right + 8, (rectangle.top + rectangle.bottom - tm.tmHeight) / 2, ::wchar(txt), txt.size() - 1); } else { std::string colorString = "("; ZLStringUtil::appendNumber(colorString, color.Red); colorString += ","; ZLStringUtil::appendNumber(colorString, color.Green); colorString += ","; ZLStringUtil::appendNumber(colorString, color.Blue); colorString += ")"; TextOutA(di.hDC, rectangle.right + 8, (rectangle.top + rectangle.bottom - tm.tmHeight) / 2, colorString.data(), colorString.length()); } }
void Fl_Device::rtl_draw(const char *str, int n, float x, float y) { // USE BUFFER HERE ALSO SetTextColor(fl_gc, fl_colorref); SelectObject(fl_gc, current_font); int i = 0; int lx = 0; const WCHAR *skod; resize_buffer(n); int wn = fl_utf2unicode((const unsigned char *)str, n, wstr); while (i < wn) { lx = int(fl_width(wstr[i])); x -= lx; skod = (const WCHAR*)wstr + i; #ifndef _WIN32_WCE TextOutW(fl_gc, int(floor(x+.5f)), int(floor(y+.5f)), skod, 1); #else RECT rect = {int(floor(x+.5f)),int(floor(y+.5f)), 0,0}; DrawText(fl_gc, skod, 1, &rect, DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOCLIP); #endif if (fl_nonspacing(wstr[i])) { x += lx; } i++; } }
void App::DrawInfoText(HDC hdc, int x, int y) { HFONT arial_font; HFONT old_font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfItalic = false; lf.lfUnderline = false; lf.lfStrikeOut = false; lf.lfOrientation = 0; lf.lfWeight = FW_NORMAL; lf.lfHeight = -8; lstrcpy(lf.lfFaceName, L"Arial"); arial_font = CreateFontIndirect(&lf); old_font = (HFONT)::SelectObject(hdc, arial_font); std::wstring display_text = L"There are "; // I'm sure I can make this with m_bunnies.size() display_text += helpers::IntToString(Bunny::get_bunnies_overall()); display_text += L" bunnies"; TextOutW(hdc, x, y, display_text.c_str(), display_text.length()); SelectObject(hdc, old_font); DeleteObject(arial_font); }
void DrawNormal(const Chat &chat, int vpos) { int x = static_cast<int>(rcWnd_.right - (float)(chat.width + rcWnd_.right) * (vpos - chat.vpos) / VPOS_LEN); int y = static_cast<int>(((float)yPitch_ * CNJIni::GetSettings()->commentLineMargin) * (float)chat.line); int shadow = (yPitch_ / 16); if ( yPitch_ > 24 && shadow == 1 ) { shadow = 2; } if ( shadow < 1 ) { shadow = 1; } const std::wstring &text = chat.text; SetTextColor(memDC_, RGB(0, 0, 0)); TextOutW(memDC_, x+shadow, y+shadow, text.c_str(), text.length()); SetTextColor(memDC_, chat.color); TextOutW(memDC_, x, y, text.c_str(), text.length()); }
// Draws a cross-hatch and labels the cX, cY point. BOOL dpi_Label(HDC hdc, double cX, double cY, COLORREF color, HFONT font, UINT align) { wchar_t tmp[16]; swprintf(tmp, 16, L"%-2.3f, %-2.3f", cX, cY); UINT old_ta = GetTextAlign(hdc); COLORREF old_color = GetTextColor(hdc); HFONT old_font = GetCurrentObject(hdc, OBJ_FONT); HPEN old_pen = GetCurrentObject(hdc, OBJ_PEN); SetTextColor(hdc, color); SetTextAlign(hdc, align); // TA_CENTER | VTA_TOP SelectObject(hdc, font); SelectObject(hdc, GetStockObject(WHITE_PEN)); // Draw cross-hair: dpi_MoveTo(hdc, cX, cY - 0.05); dpi_LineTo(hdc, cX, cY + 0.0525); dpi_MoveTo(hdc, cX - 0.05, cY); dpi_LineTo(hdc, cX + 0.0525, cY); // Label: BOOL ret = TextOutW(hdc, (int)(cX * dpi), (int)(cY * dpi), tmp, (int)wcslen(tmp)); SelectObject(hdc, old_pen); SelectObject(hdc, old_font); SetTextAlign(hdc, old_ta); SetTextColor(hdc, old_color); return ret; }
static bool text(int x, int y, const char *text, size_t length, const plot_font_style_t *style) { PLOT_LOG("words %s at %d,%d", text, x, y); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG("HDC not set on call to plotters"); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } HFONT fontbak, font = get_font(style); if (font == NULL) { DeleteObject(clipregion); return false; } int wlen; SIZE s; LPWSTR wstring; fontbak = (HFONT) SelectObject(plot_hdc, font); GetTextExtentPoint(plot_hdc, text, length, &s); /* RECT r; r.left = x; r.top = y - (3 * s.cy) / 4; r.right = x + s.cx; r.bottom = y + s.cy / 4; */ SelectClipRgn(plot_hdc, clipregion); SetTextAlign(plot_hdc, TA_BASELINE | TA_LEFT); if ((style->background & 0xFF000000) != 0x01000000) /* 100% alpha */ SetBkColor(plot_hdc, (DWORD) (style->background & 0x00FFFFFF)); SetBkMode(plot_hdc, TRANSPARENT); SetTextColor(plot_hdc, (DWORD) (style->foreground & 0x00FFFFFF)); wlen = MultiByteToWideChar(CP_UTF8, 0, text, length, NULL, 0); wstring = malloc(2 * (wlen + 1)); if (wstring == NULL) { return false; } MultiByteToWideChar(CP_UTF8, 0, text, length, wstring, wlen); TextOutW(plot_hdc, x, y, wstring, wlen); SelectClipRgn(plot_hdc, NULL); free(wstring); font = SelectObject(plot_hdc, fontbak); DeleteObject(clipregion); DeleteObject(font); return true; }
static void ME_DebugWrite(HDC hDC, POINT *pt, WCHAR *szText) { int align = SetTextAlign(hDC, TA_LEFT|TA_TOP); HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT)); COLORREF color = SetTextColor(hDC, RGB(128,128,128)); TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText)); SelectObject(hDC, hFont); SetTextAlign(hDC, align); SetTextColor(hDC, color); }
void EmfPaintEngine::drawTextItem ( const QPointF & p, const QTextItem & textItem ) { setClipping(); SetBkMode( metaDC, TRANSPARENT ); QFont f = textItem.font(); QFontMetrics fm(f); HFONT wfont = CreateFontA(fm.height() - 1, fm.averageCharWidth(), 0, 0, 10*f.weight(), f.italic(), f.underline (), f.strikeOut(), DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, f.family().toAscii().data()); SelectObject( metaDC, wfont); QColor colour = painter()->pen().color(); SetTextColor( metaDC, RGB(colour.red(), colour.green(), colour.blue())); QString text = textItem.text(); int size = text.size(); QMatrix m = painter()->worldMatrix(); XFORM xf; xf.eM11 = m.m11(); xf.eM12 = m.m12(); xf.eM21 = m.m21(); xf.eM22 = m.m22(); xf.eDx = m.dx(); xf.eDy = m.dy(); SetWorldTransform(metaDC, &xf); #ifdef Q_WS_WIN wchar_t *wtext = (wchar_t *)malloc(size*sizeof(wchar_t)); if (!wtext){ qWarning("EmfEngine: Not enough memory in drawTextItem()."); return; } size = text.toWCharArray(wtext); TextOutW(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), wtext, size); free(wtext); #else TextOutA(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), text.toLocal8Bit().data(), size); #endif xf.eM11 = 1.0; xf.eM12 = 0.0; xf.eM21 = 0.0; xf.eM22 = 1.0; xf.eDx = 0.0; xf.eDy = 0.0; SetWorldTransform(metaDC, &xf); resetClipping(); DeleteObject(wfont); }
void TextOutWH(HDC hDC, int x, int y, WCHAR text[], int len) { TEXTMETRIC tm; GetTextMetrics(hDC, & tm); for (int i=0; i<len; i++) { TextOutW(hDC, x, y, & text[i], 1); if (i==0) y+=40; else y+= 45; } }
void ExecutionLogWindow::PaintSimpleContent(HWND hwnd, PAINTSTRUCT* pps) { HFONT hfPrev = SelectFont(pps->hdc, m_hfList); /* Use the right font */ int iMin = max(pps->rcPaint.top / m_cyLine, 0); int iMax = min((pps->rcPaint.bottom + m_cyLine - 1) / m_cyLine, (int)m_lines.size()); for (int i = iMin; i != iMax; ++i) { BOOST_ASSERT(i >= 0 && i < (int)m_lines.size()); TextOutW(pps->hdc, 0, i * m_cyLine, m_lines[i].c_str(), (int)m_lines[i].length()); } SelectFont(pps->hdc, hfPrev); }
LOCAL void fb_drawtext(WINDISPLAY *mod, struct TVRequest *req) { WINWINDOW *win = req->tvr_Op.Text.Window; const char *text = req->tvr_Op.Text.Text; TINT len = req->tvr_Op.Text.Length; TUINT x = req->tvr_Op.Text.X; TUINT y = req->tvr_Op.Text.Y; struct FBPen *fgpen = (struct FBPen *) req->tvr_Op.Text.FgPen; int clen = utf8getlen((const unsigned char *) text, len); TUINT16 wstr[2048]; MultiByteToWideChar(CP_UTF8, 0, text, len, (LPWSTR) &wstr, 2048); SetTextColor(win->fbv_HDC, fgpen->col); TextOutW(win->fbv_HDC, x, y, wstr, clen); }
void RenderGlyph(int inChar, const RenderTarget &outTarget) { if (!sGammaLUTInit) { double pow_max = 255.0/pow(255,1.9); for(int i=0;i<256;i++) { sGammaLUT[i] = pow(i,1.9)*pow_max + 0.5; } sGammaLUTInit = true; } int w = outTarget.mRect.w; w = (w+3) & ~3; int h = outTarget.mRect.h; if (w>sgDIB_W || h>sgDIB_H) { if (sgDIB) { SelectObject(sgFontDC,sgOldDIB); DeleteObject(sgDIB); } BITMAPINFO bmi; memset(&bmi,0,sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; sgDIB_W = w; sgDIB_H = h; sgDIB = CreateDIBSection(sgFontDC,&bmi,DIB_RGB_COLORS, (void **)&sgDIBBits, 0, 0 ); sgOldDIB = (HBITMAP)SelectObject(sgFontDC,sgDIB); } memset(sgDIBBits,0,sgDIB_W*sgDIB_H*4); wchar_t ch = inChar; TextOutW(sgFontDC,0,0,&ch,1); for(int y=0;y<outTarget.mRect.h;y++) { ARGB *src = sgDIBBits + (sgDIB_H - 1 - y)*sgDIB_W; uint8 *dest = (uint8 *)outTarget.Row(y + outTarget.mRect.y) + outTarget.mRect.x; for(int x=0;x<outTarget.mRect.w;x++) *dest++= sGammaLUT[(src++)->g]; } }
void ZLWin32PaintContext::drawString(int x, int y, const char *str, int len) { if (myDisplayContext == 0) { return; } y -= stringHeight(); y += myTextMetric.tmDescent; int utf8len = ZLUnicodeUtil::utf8Length(str, len); if (utf8len == len) { TextOutA(myDisplayContext, x, y, str, len); } else { static ZLUnicodeUtil::Ucs2String ucs2Str; ucs2Str.clear(); ZLUnicodeUtil::utf8ToUcs2(ucs2Str, str, len, utf8len); TextOutW(myDisplayContext, x, y, ::wchar(ucs2Str), utf8len); } }
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...) { va_list argptr; CHAR16 string[512]; HVSURFACE hVSurface; LPDIRECTDRAWSURFACE2 pDDSurface; HDC hdc; HWINFONT *pWinFont; int len; pWinFont = GetWinFont( iFont ); if ( pWinFont == NULL ) { return; } va_start(argptr, pFontString); // Set up variable argument pointer len = vswprintf(string, pFontString, argptr); // process gprintf string (get output str) va_end(argptr); // Get surface... GetVideoSurface( &hVSurface, uiDestBuf ); pDDSurface = GetVideoSurfaceDDSurface( hVSurface ); IDirectDrawSurface2_GetDC( pDDSurface, &hdc ); SelectObject(hdc, pWinFont->hFont ); SetTextColor( hdc, pWinFont->ForeColor ); SetBkColor(hdc, pWinFont->BackColor ); SetBkMode(hdc, TRANSPARENT); SetTextAlign(hdc, TA_TOP|TA_LEFT); #ifdef DEC_INTERNAL_LEADING if (y - pWinFont->InternalLeading >=0) { y -= pWinFont->InternalLeading; } #endif TextOutW( hdc, x, y, string, len ); IDirectDrawSurface2_ReleaseDC( pDDSurface, hdc ); }
void dialog_paint_pb(HDC hDC) { HDC tdc, memdc; HBITMAP tbmp, membmp; HFONT hFont; memdc = CreateCompatibleDC(hDC); membmp = CreateCompatibleBitmap(hDC, 565, 23); SelectObject(memdc, membmp); // paint background tbmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BG)); tdc = CreateCompatibleDC(hDC); SelectObject(tdc, tbmp); BitBlt(memdc, 0, 0, 565, 23, tdc, 16, 334, SRCCOPY); DeleteDC(tdc); DeleteObject(tbmp); // paint foreground tbmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_PB)); tdc = CreateCompatibleDC(hDC); SelectObject(tdc, tbmp); BitBlt(memdc, 0, 0, progress * 565 / 100, 23, tdc, 0, 0, SRCCOPY); DeleteDC(tdc); DeleteObject(tbmp); // paint text hFont = CreateFont(16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Tahoma")); SetBkMode(memdc, TRANSPARENT); SetTextAlign(memdc, TA_CENTER); SelectObject(memdc, hFont); TextOutW(memdc, 282, 3, pb_text, (INT)wcslen(pb_text)); DeleteObject(hFont); // paint membmp onto window BitBlt(hDC, 16, 334, 565, 23, memdc, 0, 0, SRCCOPY); DeleteDC(memdc); DeleteObject(membmp); last_progress = progress; }
BOOL WINAPI ShadowTextOutW(HDC textdc, int x, int y, LPCWSTR lptext, int cb) { char szText[MAXTEXTOUT] = NULLSTR; int iLenText = 0; BOOL bRet = FALSE; BOOL bUsed = FALSE; // write text buffer iLenText = WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, lptext, cb, szText, MAXTEXTOUT, "*", &bUsed); WriteToTextBuffer((LPCSTR)szText, (UINT)iLenText); // pass on call to real function UnhookFunction((PHOOKREC)&_hrTextOutW); bRet = TextOutW(textdc, x, y, lptext, cb); HookFunction((PHOOKREC)&_hrTextOutW); return bRet; }
EXPORT BOOL CALLBACK EdrCenterTextW(HDC hdc, PRECT prc, PCWSTR pString) { int iLength; SIZE size; iLength = lstrlenW(pString); GetTextExtentPoint32W(hdc, pString, iLength, &size); return TextOutW(hdc, (prc->right - prc->left - size.cx) / 2, (prc->bottom - prc->top - size.cy) / 2, pString, iLength); }
static void DrawItem(HDC hDC, WCHAR *text, BOOL selected, int bg, int x, int y, int width, int height) { RECT r1; r1.left = x; r1.top = y; r1.right = x+width; r1.bottom = y + height; FillRect(hDC,&r1, (HBRUSH)(bg + 1)); MoveToEx(hDC, x, y, NULL); LineTo(hDC, x+width, y); LineTo(hDC, x+width, y+height); LineTo(hDC, x, y+height); LineTo(hDC, x, y); if (text) { SetBkColor(hDC, GetSysColor(bg)); TextOutW(hDC, x+3, y+1, text, wcslen(text)); } else // separator { MoveToEx(hDC, x+5, y+height/2-1, NULL); LineTo(hDC, x+width-5, y+height/2-1); MoveToEx(hDC, x+5, y+height/2, NULL); LineTo(hDC, x+width-5, y+height/2); } if (selected) { HPEN *pen = CreatePen(PS_DOT, 0, 0); pen = SelectObject(hDC, pen); MoveToEx(hDC, x+1, y+1, NULL); LineTo(hDC, x+width-1, y+1); LineTo(hDC, x+width-1, y+height-1); LineTo(hDC, x+1, y+height-1); LineTo(hDC, x+1, y+1); pen = SelectObject(hDC, pen); DeleteObject(pen); } }
/* ANT_CANVAS::RENDER_UTF8_SEGMENT() --------------------------------- */ long long ANT_canvas::render_utf8_segment(ANT_point *where, ANT_rgb *colour, char *string, long long string_length, ANT_point *text_size) { TEXTMETRIC text_metrics; SIZE size; static const long long RIGHT_MARGIN = 5; long long result; while (1) { if ((result = MultiByteToWideChar(CP_UTF8, 0, string, string_length, (LPWSTR)unicode_buffer, unicode_buffer_length / 2)) != 0) break; else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { result = MultiByteToWideChar(CP_UTF8, 0, string, string_length, NULL, 0); if (result == 0) return render_text_segment(where, colour, string, string_length, text_size); else { unicode_buffer_length = result + 2; // +2 for the L'\0' delete [] unicode_buffer; unicode_buffer = new (std::nothrow) char [unicode_buffer_length]; } } else return render_text_segment(where, colour, string, string_length, text_size); } SelectObject(hDC, unicode_font); SetTextColor(hDC, RGB(colour->red, colour->green, colour->blue)); TextOutW(hDC, where->x + RIGHT_MARGIN, where->y, (LPWSTR)unicode_buffer, result); GetTextExtentPointW(hDC, (LPWSTR)unicode_buffer, result, &size); text_size->x = size.cx; text_size->y = size.cy; return string_length; }
static void EmuPrint_RAW( W32_PRINTER_INFO *pInfo, const void *pText, size_t uiLength, int isunicode ) { while( uiLength-- ) { if( !isunicode ) { char ch = *(char *)pText; pText += sizeof(char); EmuPageStart( pInfo ); TextOut( pInfo->hDc, pInfo->Emu.dwCurrentX, pInfo->Emu.dwCurrentY, &ch, 1 ); } else { FB_WCHAR ch = *(FB_WCHAR *)pText; pText += sizeof(FB_WCHAR); EmuPageStart( pInfo ); TextOutW( pInfo->hDc, pInfo->Emu.dwCurrentX, pInfo->Emu.dwCurrentY, &ch, 1 ); } pInfo->Emu.dwCurrentX += pInfo->Emu.dwFontSizeX; if( pInfo->Emu.dwCurrentX>=pInfo->Emu.dwSizeX ) { pInfo->Emu.dwCurrentX = 0; pInfo->Emu.dwCurrentY += pInfo->Emu.dwFontSizeY; if( pInfo->Emu.dwCurrentY>=pInfo->Emu.dwSizeY ) { pInfo->Emu.dwCurrentY = 0; EndPage( pInfo->hDc ); pInfo->Emu.iPageStarted = FALSE; } } } }
void dispW(HWND hwnd, const TCHAR* str, ...) { va_list args; va_start(args, str); ZeroMemory(msg, TXTCOUNT); vswprintf(msg, TXTCOUNT / 2, str, args); va_end(args); HFONT hfont, hOldfont; HDC hdc; hfont = (HFONT)GetStockObject(SYSTEM_FONT); hdc = GetDC(hwnd); hOldfont = (HFONT)SelectObject(hdc, hfont); if (hOldfont){ TextOutW(hdc, 5, text_cnt * 20, msg, lstrlenW(msg)); SelectObject(hdc, hOldfont); } ReleaseDC(hwnd, hdc); text_cnt++; }
LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch (msg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); TextOutW(hdc, 0, 0, L"Hello World!", (int)wcslen(L"Hello World!")); EndPaint(hwnd, &ps); break; default: return DefWindowProc(hwnd, msg, wparam, lparam); break; } return 0; }
GlyphPath* GlyphPathCache::Create(HDC hDC, const FontWrapper* f, WCHAR c) { CStringW key = CStringW((LPCWSTR)*f) + c; GlyphPath* path = NULL; if(m_key2obj.Lookup(key, path)) { return path; } BeginPath(hDC); TextOutW(hDC, 0, 0, &c, 1); CloseFigure(hDC); if(!EndPath(hDC)) { AbortPath(hDC); ASSERT(0); return NULL; } path = DNew GlyphPath(); int count = GetPath(hDC, NULL, NULL, 0); if(count > 0) { path->points.SetCount(count); path->types.SetCount(count); if(count != GetPath(hDC, path->points.GetData(), path->types.GetData(), count)) { ASSERT(0); delete path; return NULL; } } Add(key, path); return path; }
static void HOTKEY_DrawHotKey(HOTKEY_INFO *infoPtr, HDC hdc, LPCWSTR KeyName, WORD NameLen) { SIZE TextSize; INT nXStart, nYStart; COLORREF clrOldText, clrOldBk; HFONT hFontOld; /* Make a gap from the frame */ nXStart = GetSystemMetrics(SM_CXBORDER); nYStart = GetSystemMetrics(SM_CYBORDER); hFontOld = SelectObject(hdc, infoPtr->hFont); if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & WS_DISABLED) { clrOldText = SetTextColor(hdc, comctl32_color.clrGrayText); clrOldBk = SetBkColor(hdc, comctl32_color.clrBtnFace); } else { clrOldText = SetTextColor(hdc, comctl32_color.clrWindowText); clrOldBk = SetBkColor(hdc, comctl32_color.clrWindow); } TextOutW(hdc, nXStart, nYStart, KeyName, NameLen); /* Get the text width for the caret */ GetTextExtentPoint32W(hdc, KeyName, NameLen, &TextSize); infoPtr->CaretPos = nXStart + TextSize.cx; SetBkColor(hdc, clrOldBk); SetTextColor(hdc, clrOldText); SelectObject(hdc, hFontOld); /* position the caret */ SetCaretPos(infoPtr->CaretPos, nYStart); }
void NFOView::DrawHyperlink(void) { RECT viewWindowRect; GetClientRect(_handle, &viewWindowRect); HDC viewWindowDC = GetDC(_handle); HFONT hFont = (HFONT)SendMessage(_handle, WM_GETFONT, NULL, NULL); SelectObject(viewWindowDC, hFont); SetBkMode(viewWindowDC, TRANSPARENT); IntersectClipRect(viewWindowDC, viewWindowRect.left, viewWindowRect.top, viewWindowRect.right, viewWindowRect.bottom); SetTextColor(viewWindowDC, RGB(0, 102, 204)); DWORD selStart; DWORD selEnd; SendMessage(_handle, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd); for (int i = 0; i < _hyperlinkOffsets.size(); i++) { for (int charIndex = _hyperlinkOffsets[i].start; charIndex <= _hyperlinkOffsets[i].end; charIndex++) { DWORD pos = SendMessage(_handle, EM_POSFROMCHAR, (WPARAM)charIndex, NULL); POINT charPt = {LOWORD(pos), HIWORD(pos)}; // don't draw text that selected if (selStart != selEnd && charIndex >= selStart && charIndex < selEnd) { continue; } TextOutW(viewWindowDC, charPt.x, charPt.y, _nfoText.c_str()+charIndex, 1); } } ReleaseDC(_handle, viewWindowDC); }
BOOL WINAPI MyTextOutA(HDC hDC, int nXStart, int nYStart, LPCTSTR lpString, int cbCount) { BOOL r; WCHAR c, ch[0x100]; ULONG CodePage; CodePage = CP_GB2312; if (cbCount > 2 && IsShiftJISString((PCHAR)lpString, cbCount)) { CodePage = CP_SHIFTJIS; } else if (cbCount == 2) { c = *(PWCHAR)lpString; switch (c) { case SWAPCHAR('‘Ρ'): ch[0] = 0x266A; goto SKIP_CONV; default: if (IsShiftJISChar(SWAPCHAR(c))) CodePage = CP_SHIFTJIS; goto NOT_CHANGE_CHAR; } } NOT_CHANGE_CHAR: CodePage = MultiByteToWideChar(CodePage, 0, lpString, cbCount, ch, countof(ch)); SKIP_CONV: r = TextOutW(hDC, nXStart, nYStart, ch, CodePage); return r; }
BOOL WINAPI IntGrayString( HDC hDC, HBRUSH hBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int X, int Y, int nWidth, int nHeight, BOOL unicode) { // AG: Mostly implemented, but probably won't work properly or return // correct error codes. I doubt it grays strings either... Untested! BOOL success = FALSE; HBRUSH hbsave; HDC MemDC = NULL; HBITMAP MemBMP = NULL, OldBMP = NULL; HBRUSH OldBrush = NULL; HFONT OldFont = NULL; RECT r; COLORREF ForeColor, BackColor; ForeColor = SetTextColor(hDC, RGB(0, 0, 0)); BackColor = SetBkColor(hDC, RGB(255, 255, 255)); if (! hBrush) { // The documentation is a little vague on what exactly should happen // here. Something about using the same brush for window text??? hBrush = (HBRUSH) GetCurrentObject(hDC, OBJ_BRUSH); } if ((nCount == -1) && (! lpOutputFunc)) return FALSE; if (! nCount) { // TODO: calculate the length (easy enough) if (unicode) nCount = lstrlenW((WCHAR*)lpData); else nCount = lstrlenA((CHAR*)lpData); } if (! nWidth || ! nHeight) { SIZE s; // TODO: calculate the rect if (unicode) success = GetTextExtentPoint32W(hDC, (WCHAR*) lpData, nCount, &s); else success = GetTextExtentPoint32A(hDC, (CHAR*) lpData, nCount, &s); if (! success) goto cleanup; if (! nWidth) nWidth = s.cx; if (! nHeight) nHeight = s.cy; } SetRect(&r, X, Y, X + nWidth, Y + nHeight); MemDC = CreateCompatibleDC(hDC); if (! MemDC) goto cleanup; MemBMP = CreateBitmap(nWidth, nHeight, 1, 1, NULL); if (! MemBMP) goto cleanup; OldBMP = SelectObject(MemDC, MemBMP); if (! OldBMP) goto cleanup; OldFont = SelectObject(MemDC, GetCurrentObject(hDC, OBJ_FONT)); if (! OldFont) goto cleanup; OldBrush = SelectObject(MemDC, hBrush); if (! OldBrush) goto cleanup; if (! BitBlt(MemDC, 0, 0, nWidth, nHeight, hDC, X, Y, SRCCOPY)) goto cleanup; SetTextColor(MemDC, RGB(255, 255, 255)); SetBkColor(MemDC, RGB(0, 0, 0)); if (lpOutputFunc) { success = lpOutputFunc(MemDC, lpData, nCount); // Set brush etc first? if ((nCount == -1) && (! success)) { // Don't gray (documented behaviour) success = (BOOL) BitBlt(hDC, X, Y, nWidth, nHeight, MemDC, 0, 0, SRCCOPY); goto cleanup; } } else { if (unicode) success = TextOutW(MemDC, 0, 0, (WCHAR*) lpData, nCount); else success = TextOutA(MemDC, 0, 0, (CHAR*) lpData, nCount); if (! success) goto cleanup; hbsave = (HBRUSH)SelectObject(MemDC, gpsi->hbrGray); PatBlt(MemDC, 0, 0, nWidth, nHeight, 0x000A0329); SelectObject(MemDC, hbsave); } if (! BitBlt(hDC, X, Y, nWidth, nHeight, MemDC, 0, 0, SRCCOPY)) goto cleanup; cleanup: SetTextColor(hDC, ForeColor); SetBkColor(hDC, BackColor); if (MemDC) { if (OldFont) SelectObject(MemDC, OldFont); if (OldBrush) SelectObject(MemDC, OldBrush); if (OldBMP) SelectObject(MemDC, OldBMP); if (MemBMP) DeleteObject(MemBMP); DeleteDC(MemDC); } return success; }
//handles actually creating the associated texture given the list of glyphs that have their positioning //and dimension information filled out static bool CreateGlyphTexture(CTextureStringGlyph* pGlyphs, uint32 nNumGlyphs, HDC hDC, uint8* pDibBits, const BITMAPINFO& bmi, const TEXTMETRICW& textMetric, HTEXTURE & hTexture) { //run through and build up the maximum extents from the glyph black boxes uint32 nMaxWidth = 0; uint32 nMaxHeight = 0; for(uint32 nCurrGlyph = 0; nCurrGlyph < nNumGlyphs; nCurrGlyph++) { nMaxWidth = LTMAX(nMaxWidth, pGlyphs[nCurrGlyph].m_rBlackBox.GetWidth()); nMaxHeight = LTMAX(nMaxHeight, pGlyphs[nCurrGlyph].m_rBlackBox.GetHeight()); } //the spacing added to each glyph dimension const uint32 knCharSpacing = 2; //determine the size of this texture that we will need SIZE sizeTexture; if(!GetTextureSizeFromCharSizes(pGlyphs, nNumGlyphs, nMaxWidth, nMaxHeight, knCharSpacing, sizeTexture )) { //the font is to big to fit into a texture, we must fail return false; } // This will be filled in with the pixel data of the font. uint8* pImageData = NULL; //lock down our texture for writing // uint32 nWidth, nHeight, uint32 nPitch; // uint8* pImageData; // Calculate the pixeldata pitch. nPitch = WIDTHBYTES( 16, sizeTexture.cx ); int nPixelDataSize = nPitch * sizeTexture.cy; // Allocate an array to copy the font into. LT_MEM_TRACK_ALLOC( pImageData = new uint8[ nPixelDataSize ],LT_MEM_TYPE_UI ); if ( pImageData == NULL ) { DEBUG_PRINT( 1, ("CreateGlyphTexture: Failed to allocate pixeldata." )); return false; } // set the whole font texture to pure white, with alpha of 0. When // we copy the glyph from the bitmap to the pixeldata, we just // affect the alpha, which allows the font to antialias with any color. uint16* pData = (uint16*)pImageData; uint16* pPixelDataEnd = (uint16*)(pImageData + nPixelDataSize); while( pData < pPixelDataEnd ) { pData[0] = 0x0FFF; pData++; } // This will hold the UV offset for the font texture. POINT sizeOffset; sizeOffset.x = 0; sizeOffset.y = 0; //success flag bool bSuccess = true; // Iterate over the characters. for( uint32 nGlyph = 0; nGlyph < nNumGlyphs; nGlyph++ ) { // Clear the bitmap out for this glyph if it's not the first. The first glyph // gets a brand new bitmap to write on. if( nGlyph != 0 ) { memset( pDibBits, 0, bmi.bmiHeader.biSizeImage ); } //cache the glyph we will be operating on CTextureStringGlyph& Glyph = pGlyphs[nGlyph]; // Get this character's width. wchar_t cChar = Glyph.m_cGlyph; int nCharWidthWithSpacing = Glyph.m_rBlackBox.GetWidth() + knCharSpacing; // See if this width fits in the current row. int nCharRightSide = sizeOffset.x + nCharWidthWithSpacing; if( nCharRightSide >= sizeTexture.cx ) { // Doesn't fit in the current row. Go to the next row. sizeOffset.x = 0; sizeOffset.y += nMaxHeight + knCharSpacing; } // Write the glyph out so that the smallest box around the glyph starts // at the bitmap's 0,0. POINT ptTextOutOffset; ptTextOutOffset.x = -Glyph.m_rBlackBox.Left(); ptTextOutOffset.y = -Glyph.m_rBlackBox.Top(); // Write out the glyph. We can't use GetGlyphOutline to get the bitmap since // it has a lot of corruption bugs with it. if( !TextOutW( hDC, ptTextOutOffset.x, ptTextOutOffset.y, &cChar, 1 )) { bSuccess = false; break; } // Make sure the GDI is done with our bitmap. GdiFlush( ); LTRect2n rCopyTo; rCopyTo.Left() = sizeOffset.x + (knCharSpacing / 2); rCopyTo.Top() = sizeOffset.y + (knCharSpacing / 2); rCopyTo.Right() = rCopyTo.Left() + Glyph.m_rBlackBox.GetWidth(); rCopyTo.Bottom() = rCopyTo.Top() + Glyph.m_rBlackBox.GetHeight(); // Find pointer to region within the pixel data to copy the glyph // and copy the glyph into the pixeldata. CopyGlyphBitmapToPixelData( bmi, pDibBits, rCopyTo, textMetric, pImageData, sizeTexture ); //setup the UV coordinates for this glyph Glyph.m_fU = (float)(rCopyTo.Left() + 0.5f) / (float)sizeTexture.cx; Glyph.m_fV = (float)(rCopyTo.Top() + 0.5f) / (float)sizeTexture.cy; Glyph.m_fTexWidth = rCopyTo.GetWidth() / (float)sizeTexture.cx; Glyph.m_fTexHeight = rCopyTo.GetHeight() / (float)sizeTexture.cy; // Update to the next offset for the next character. sizeOffset.x += nCharWidthWithSpacing; } //if we succeeded in rendering all the characters, convert it to a texture if(bSuccess) { // turn pixeldata into a texture g_pILTTextureMgr->CreateTextureFromData( hTexture, TEXTURETYPE_ARGB4444, TEXTUREFLAG_PREFER16BIT | TEXTUREFLAG_PREFER4444, pImageData, sizeTexture.cx, sizeTexture.cy ); if( !hTexture ) { DEBUG_PRINT( 1, ("CreateGlyphTexture: Couldn't create texture." )); bSuccess = false; } } // Don't need pixel data any more. if( pImageData ) { delete[] pImageData; pImageData = NULL; } //return the success code return bSuccess; }