Ejemplo n.º 1
0
 ~BitmapDC()
 {
     prepareBitmap(0, 0);
     if (m_hDC)
     {
         DeleteDC(m_hDC);
     }
     HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
     if (hDefFont != m_hFont)
     {
         DeleteObject(m_hFont);
         m_hFont = hDefFont;
     }
     // release temp font resource
     if (m_curFontPath.size() > 0)
     {
         wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
         if (pwszBuffer)
         {
             RemoveFontResourceW(pwszBuffer);
             SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
             delete [] pwszBuffer;
             pwszBuffer = NULL;
         }
     }
 }
	bool drawText(const char *pszText, int nWidth, int nHeight, CCImage::ETextAlign eAlignMask)
    {
        bool bRet = false;

        do 
        {
            CC_BREAK_IF(! pszText);

            CC_BREAK_IF(! prepareBitmap(nWidth, nHeight));

			/* create canvas */
			SkPaint::FontMetrics font;
			m_pPaint->getFontMetrics(&font);
			SkCanvas canvas(*m_pBitmap);

			/*
			 * draw text
			 * @todo: alignment
			 */
			canvas.drawText(pszText, strlen(pszText), 0.0, -font.fAscent, *m_pPaint);
			bRet = true;
        } while (0);

        return bRet;
    }
Ejemplo n.º 3
0
 ~BitmapDC()
 {
     prepareBitmap(0, 0);
     if (m_hDC)
     {
         DeleteDC(m_hDC);
     }
 }
Ejemplo n.º 4
0
 ~BitmapDC()
 {
     prepareBitmap(0, 0);
     if (_DC)
     {
         DeleteDC(_DC);
     }
     removeCustomFont();
 }
Ejemplo n.º 5
0
 bool createDeviceResource() {
     DPTR_P(Direct2DRenderer);
     update_background = true;
     destroyDeviceResource();
     //
     //  This method creates resources which are bound to a particular
     //  Direct3D device. It's all centralized here, in case the resources
     //  need to be recreated in case of Direct3D device loss (eg. display
     //  change, remoting, removal of video card, etc).
     //
     //TODO: move to prepare(), or private. how to call less times
     D2D1_RENDER_TARGET_PROPERTIES rtp = {
         D2D1_RENDER_TARGET_TYPE_DEFAULT,
         pixel_format,
         0,
         0,
         D2D1_RENDER_TARGET_USAGE_NONE,
         D2D1_FEATURE_LEVEL_DEFAULT
     };
     D2D1_SIZE_U size = {
         (UINT32)p.width(),
         (UINT32)p.height()
     };//d.renderer_width, d.renderer_height?
     // Create a Direct2D render target.
     D2D1_HWND_RENDER_TARGET_PROPERTIES hwnd_rtp = {
         (HWND)p.winId(),
         size,
         //TODO: what do these mean?
         D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS //D2D1_PRESENT_OPTIONS_IMMEDIATELY /* this might need fiddling */
     };
     HRESULT hr = d2d_factory->CreateHwndRenderTarget(&rtp//D2D1::RenderTargetProperties() //TODO: vlc set properties
                                                      , &hwnd_rtp//D2D1::HwndRenderTargetProperties(, size)
                                                      , &render_target);
     if (FAILED(hr)) {
         qWarning("Direct2D is disabled. CreateHwndRenderTarget() failed: %d", (int)GetLastError());
         render_target = 0;
         return false;
     }
     SafeRelease(&bitmap);
     prepareBitmap(src_width, src_height); //bitmap depends on render target
     return hr == S_OK;
 }
Ejemplo n.º 6
0
    ~BitmapDC()
    {
        prepareBitmap(0, 0);
        if (m_hDC)
        {
            DeleteDC(m_hDC);
        }
        HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
        if (hDefFont != m_hFont)
        {
            DeleteObject(m_hFont);
            m_hFont = hDefFont;
        }
		// release temp font resource	
		if (m_curFontPath.size() > 0)
		{
			RemoveFontResource(m_curFontPath.c_str());
			SendMessage(m_hWnd, WM_FONTCHANGE, 0, 0);
		}
    }
Ejemplo n.º 7
0
    int drawText(const char * pszText, SIZE& tSize, CCImage::ETextAlign eAlign)
    {
        int nRet = 0;
        do 
        {
            CC_BREAK_IF(! pszText);

            DWORD dwFmt = DT_WORDBREAK;
            DWORD dwHoriFlag = eAlign & 0x0f;
            DWORD dwVertFlag = (eAlign & 0xf0) >> 4;

            switch (dwHoriFlag)
            {
            case 1: // left
                dwFmt |= DT_LEFT;
                break;
            case 2: // right
                dwFmt |= DT_RIGHT;
                break;
            case 3: // center
                dwFmt |= DT_CENTER;
                break;
            }

            int nLen = strlen(pszText);
            SIZE newSize = sizeWithText(pszText, nLen, dwFmt, tSize.cx);

            RECT rcText = {0};
            // if content width is 0, use text size as content size
            if (tSize.cx <= 0)
            {
                tSize = newSize;
                rcText.right  = newSize.cx;
                rcText.bottom = newSize.cy;
            }
            else
            {

                LONG offsetX = 0;
                LONG offsetY = 0;
                rcText.right = newSize.cx; // store the text width to rectangle

                // calculate text horizontal offset
                if (1 != dwHoriFlag          // and text isn't align to left
                    && newSize.cx < tSize.cx)   // and text's width less then content width,
                {                               // then need adjust offset of X.
                    offsetX = (2 == dwHoriFlag) ? tSize.cx - newSize.cx     // align to right
                        : (tSize.cx - newSize.cx) / 2;                      // align to center
                }

                // if content height is 0, use text height as content height
                // else if content height less than text height, use content height to draw text
                if (tSize.cy <= 0)
                {
                    tSize.cy = newSize.cy;
                    dwFmt   |= DT_NOCLIP;
                    rcText.bottom = newSize.cy; // store the text height to rectangle
                }
                else if (tSize.cy < newSize.cy)
                {
                    // content height larger than text height need, clip text to rect
                    rcText.bottom = tSize.cy;
                }
                else
                {
                    rcText.bottom = newSize.cy; // store the text height to rectangle

                    // content larger than text, need adjust vertical position
                    dwFmt |= DT_NOCLIP;

                    // calculate text vertical offset
                    offsetY = (2 == dwVertFlag) ? tSize.cy - newSize.cy     // align to bottom
                        : (3 == dwVertFlag) ? (tSize.cy - newSize.cy) / 2   // align to middle
                        : 0;                                                // align to top
                }

                if (offsetX || offsetY)
                {
                    OffsetRect(&rcText, offsetX, offsetY);
                }
            }

            CC_BREAK_IF(! prepareBitmap(tSize.cx, tSize.cy));

            // draw text
            HGDIOBJ hOldFont = SelectObject(m_hDC, m_hFont);
            HGDIOBJ hOldBmp  = SelectObject(m_hDC, m_hBmp);

            RECT rc = {0, 0, tSize.cx, tSize.cy};
            SetBkMode(m_hDC, TRANSPARENT);
            SetTextColor(m_hDC, RGB(255, 255, 255)); // white color
            nRet = DrawTextA(m_hDC, pszText, nLen, &rcText, dwFmt);

            SelectObject(m_hDC, hOldBmp);
            SelectObject(m_hDC, hOldFont);
        } while (0);
        return nRet;
    }
Ejemplo n.º 8
0
    int drawText(const char * pszText, SIZE& tSize, Device::TextAlign eAlign)
    {
        int nRet = 0;
        wchar_t * pwszBuffer = 0;
        do 
        {
            CC_BREAK_IF(! pszText);

            DWORD dwFmt = DT_WORDBREAK;
            DWORD dwHoriFlag = (int)eAlign & 0x0f;
            DWORD dwVertFlag = ((int)eAlign & 0xf0) >> 4;

            switch (dwHoriFlag)
            {
            case 1: // left
                dwFmt |= DT_LEFT;
                break;
            case 2: // right
                dwFmt |= DT_RIGHT;
                break;
            case 3: // center
                dwFmt |= DT_CENTER;
                break;
            }

            int nLen = strlen(pszText);
            // utf-8 to utf-16
            int nBufLen  = nLen + 1;
            pwszBuffer = new wchar_t[nBufLen];
            CC_BREAK_IF(! pwszBuffer);

            memset(pwszBuffer, 0, sizeof(wchar_t)*nBufLen);
            nLen = MultiByteToWideChar(CP_UTF8, 0, pszText, nLen, pwszBuffer, nBufLen);

            SIZE newSize = sizeWithText(pwszBuffer, nLen, dwFmt, tSize.cx);

            RECT rcText = {0};
            // if content width is 0, use text size as content size
            if (tSize.cx <= 0)
            {
                tSize = newSize;
                rcText.right  = newSize.cx;
                rcText.bottom = newSize.cy;
            }
            else
            {

                LONG offsetX = 0;
                LONG offsetY = 0;
                rcText.right = newSize.cx; // store the text width to rectangle

                // calculate text horizontal offset
                if (1 != dwHoriFlag          // and text isn't align to left
                    && newSize.cx < tSize.cx)   // and text's width less then content width,
                {                               // then need adjust offset of X.
                    offsetX = (2 == dwHoriFlag) ? tSize.cx - newSize.cx     // align to right
                        : (tSize.cx - newSize.cx) / 2;                      // align to center
                }

                // if content height is 0, use text height as content height
                // else if content height less than text height, use content height to draw text
                if (tSize.cy <= 0)
                {
                    tSize.cy = newSize.cy;
                    dwFmt   |= DT_NOCLIP;
                    rcText.bottom = newSize.cy; // store the text height to rectangle
                }
                else if (tSize.cy < newSize.cy)
                {
                    // content height larger than text height need, clip text to rect
                    rcText.bottom = tSize.cy;
                }
                else
                {
                    rcText.bottom = newSize.cy; // store the text height to rectangle

                    // content larger than text, need adjust vertical position
                    dwFmt |= DT_NOCLIP;

                    // calculate text vertical offset
                    offsetY = (2 == dwVertFlag) ? tSize.cy - newSize.cy     // align to bottom
                        : (3 == dwVertFlag) ? (tSize.cy - newSize.cy) / 2   // align to middle
                        : 0;                                                // align to top
                }

                if (offsetX || offsetY)
                {
                    OffsetRect(&rcText, offsetX, offsetY);
                }
            }

            CC_BREAK_IF(! prepareBitmap(tSize.cx, tSize.cy));

            // draw text
            HGDIOBJ hOldFont = SelectObject(_DC, _font);
            HGDIOBJ hOldBmp  = SelectObject(_DC, _bmp);

            SetBkMode(_DC, TRANSPARENT);
            SetTextColor(_DC, RGB(255, 255, 255)); // white color

            // draw text
            nRet = DrawTextW(_DC, pwszBuffer, nLen, &rcText, dwFmt);
            //DrawTextA(_DC, pszText, nLen, &rcText, dwFmt);

            SelectObject(_DC, hOldBmp);
            SelectObject(_DC, hOldFont);
        } while (0);
        CC_SAFE_DELETE_ARRAY(pwszBuffer);
        return nRet;
    }
Ejemplo n.º 9
0
 ~BitmapDC(void)
 {
     prepareBitmap(0, 0);
 }
Ejemplo n.º 10
0
    int drawText(TUChar* pszText, int nLen, TSize& tSize, UInt32 style)
    {
        int nRet = 0;
        do 
        {
            CC_BREAK_IF(! pszText);

            if (tSize.Width() <= 0 || tSize.Height() <= 0)
            {
                CC_BREAK_IF(! getTextExtentPoint(pszText, nLen, tSize));
            }
            CC_BREAK_IF(tSize.Width() <= 0 || tSize.Height() <= 0);

            CC_BREAK_IF(! prepareBitmap(tSize.Width(), tSize.Height()));

            Int32 nWidth  = tSize.Width();
            Int32 nHeight = tSize.Height();

            // create memory window
            if (m_pMemWnd)
            {
                TRectangle rcMemWnd(0, 0, 0, 0);
                m_pMemWnd->GetClientBounds(&rcMemWnd);
                if (rcMemWnd.Width() < nWidth || rcMemWnd.Height() < nHeight)
                {
                    m_pMemWnd->CloseWindow();
                    m_pMemWnd = NULL;
                }
            }

            do 
            {
                // if memory window is already break
                CC_BREAK_IF(m_pMemWnd);

                TApplication* pApp = TApplication::GetCurrentApplication();
                CC_BREAK_IF(! pApp || ! (m_pMemWnd = new TWindow(pApp)));

                Coord nCurrentWidth = pApp->GetScreenWidth();
                Coord nCurrentHeight = pApp->GetScreenHeight();

                Coord nMemWndW = (nWidth >= nCurrentWidth) ? nWidth : nCurrentWidth;
                Coord nMemWndH = (nHeight >= nCurrentHeight) ? nHeight : nCurrentHeight;
                CC_BREAK_IF(m_pMemWnd->CreateMemWindow(nMemWndW, nMemWndH,screenAlphaFormat));
                delete m_pMemWnd;
                m_pMemWnd = NULL;
            } while (0);
            CC_BREAK_IF(! m_pMemWnd);

            // create DC
            TDC dc(m_pMemWnd);

            // draw text
            m_pMemWnd->GetMemWindowTBitmapPtr()->Fill32(RGBA(0, 0, 0, 0), 0, 0, nWidth, nHeight);

            TRectangle rect(0, 0, nWidth, nHeight);
            dc.DrawTextInRectangleEx(pszText, 0, RGBA(255,255,255,255), RGBA(0,0,0,255), m_hFont, &rect, style);

            dc.ReadBitmap(m_pBmp, 0, 0);

            nRet = true;
        } while (0);
        return nRet;
    }