void RenderContext::CalcStringSizeWithFlags(const wchar_t* text, size_t text_len, const Font& font, const Size& sz, int flags, Size& out, size_t* len /*= NULL*/, int* lines /*= NULL*/) { HDC hdc = GetDC(NULL); Gdiplus::Graphics graphics(hdc); Gdiplus::Font gdi_font(hdc, font.ToHFONT()); Gdiplus::StringFormat format; Gdiplus::RectF rectF(0, 0, sz.width(), sz.height()); Gdiplus::RectF outF; GetStringFormat(format, flags); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.MeasureString(text, text_len, &gdi_font, rectF, &format, &outF, (int*)len, lines); out.SetSize(outF.Width, outF.Height); ::ReleaseDC(NULL, hdc); }
void ESChildPreActionControl::OnPaintClient(_DC* pDC, Rect* pRectDC, Rect* pRectClient){ Image* pImage = m_bActiveState ? GetActiveImage() : GetDefaultImage(); COLORREF crText = m_bActiveState ? m_crTextActive : m_crTextDefault; float fZoomCX = 1.0f, fZoomCY = 1.0f; m_pOwner->GetZoom(fZoomCX, fZoomCY); if( fZoomCX == 1.0f ) m_nTextLeftOffsetScaled = m_nTextLeftOffset; Size szImage; Rect rcClient = GetClientRect(); if( pImage && !pImage->IsNull() ){ szImage.SetSize(pImage->GetWidth()*fZoomCX, pImage->GetHeight()*fZoomCY); if( m_bActiveState ){ if( fZoomCX == 1.0f && fZoomCY == 1.0f ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), pImage, m_rcOmitborder); else{ if( !m_imageActiveBg_Scaled.IsNull() && m_imageActiveBg_Scaled.GetWidth() == szImage.cx && m_imageActiveBg_Scaled.GetHeight() == szImage.cy ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), &m_imageActiveBg_Scaled, m_rcOmitborder_Scaled); else{ ImageDef hDestScaled = NULL; if( pImage->ScaleBitmap(ScaleMode::ScaleMode_Bilinier, szImage.cx, szImage.cy, Rect(0, 0, szImage.cx, szImage.cy), hDestScaled, true) ){ m_imageActiveBg_Scaled.Destroy(); m_imageActiveBg_Scaled.Attach(hDestScaled); m_rcOmitborder_Scaled = Rect(m_rcOmitborder.left*fZoomCX, m_rcOmitborder.top*fZoomCY, m_rcOmitborder.right*fZoomCX, m_rcOmitborder.bottom*fZoomCY); m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), &m_imageActiveBg_Scaled, m_rcOmitborder_Scaled); } } } } else{ if( fZoomCX == 1.0f && fZoomCY == 1.0f ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), pImage, m_rcOmitborder); else{ if( !m_imagDefaultBg_Scaled.IsNull() && m_imagDefaultBg_Scaled.GetWidth() == szImage.cx && m_imagDefaultBg_Scaled.GetHeight() == szImage.cy ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), &m_imagDefaultBg_Scaled, m_rcOmitborder_Scaled); else{ ImageDef hDestScaled = NULL; if( pImage->ScaleBitmap(ScaleMode::ScaleMode_Bilinier, szImage.cx, szImage.cy, Rect(0, 0, szImage.cx, szImage.cy), hDestScaled, true) ){ m_imagDefaultBg_Scaled.Destroy(); m_imagDefaultBg_Scaled.Attach(hDestScaled); m_rcOmitborder_Scaled = Rect(m_rcOmitborder.left*fZoomCX, m_rcOmitborder.top*fZoomCY, m_rcOmitborder.right*fZoomCX, m_rcOmitborder.bottom*fZoomCY); m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_OmitBorderedImage, RGB(0, 0, 0), &m_imagDefaultBg_Scaled, m_rcOmitborder_Scaled); } } } } } // Draw text. {{ Size szText; if( m_sLabelLocal.length() ){ Font fontText; m_fontText.StretchedTextFont(&fontText, fZoomCX, fZoomCY); fontText.GetTextSize(&m_sLabelLocal, szText); FONTDef pFontOld = pDC->SelectObject(fontText); // Translate from window pixel to DC pixel.{{ Point ptLabel; ptLabel.x = ((rcClient.left + m_nTextLeftOffsetScaled /*(rcClient.Width() - szText.cx)/2*/) - pRectClient->left) + pRectDC->left; ptLabel.y = ((rcClient.top + (rcClient.Height() - szText.cy)/2) - pRectClient->top) + pRectDC->top; //}} pDC->SetBkMode (TRANSPARENT); pDC->SetTextColor (crText); pDC->ExtTextOut (ptLabel.x, ptLabel.y, ETO_CLIPPED, pRectDC, m_sLabelLocal); pDC->SelectObject (pFontOld); } ESChildControl::OnPaintClient(pDC, pRectDC, pRectClient); }