Data Device::getTextureDataForText(const char * text,const FontDefinition& textDefinition,TextAlign align,int &width,int &height) { Data ret; do { BitmapDC &dc = sharedBitmapDC(); if(! dc.getBitmapFromJavaShadowStroke(text, (int)textDefinition._dimensions.width, (int)textDefinition._dimensions.height, align, textDefinition._fontName.c_str(), textDefinition._fontSize, textDefinition._fontFillColor.r / 255.0f, textDefinition._fontFillColor.g / 255.0f, textDefinition._fontFillColor.b / 255.0f, textDefinition._shadow._shadowEnabled, textDefinition._shadow._shadowOffset.width, textDefinition._shadow._shadowOffset.height, textDefinition._shadow._shadowBlur, textDefinition._shadow._shadowOpacity, textDefinition._stroke._strokeEnabled, textDefinition._stroke._strokeColor.r / 255.0f, textDefinition._stroke._strokeColor.g / 255.0f, textDefinition._stroke._strokeColor.b / 255.0f, textDefinition._stroke._strokeSize )) { break;}; width = dc._width; height = dc._height; ret.fastSet(dc._data,width * height * 4); } while (0); return ret; }
Data Device::getTextureDataForText(const char *text, const FontDefinition &textDefinition, TextAlign align, int &width, int &height) { Data _retData = Data::Null; do { CC_BREAK_IF(text == NULL); BitmapDC& _dc = sharedBitmapDC(); bool bRet = false; QSize size; size.setWidth(width); size.setHeight(height); /// draw the text on the bitmap DC. bRet = _dc.drawText(text, size, textDefinition, textDefinition._fontName.c_str(), textDefinition._fontSize); CC_BREAK_IF(bRet == false); unsigned long nLen = 0l; #if (QT_VERSION < QT_VERSION_CHECK(5, 0,0)) nLen = _dc.m_pImage->numBytes(); #else nLen = _dc.m_pImage->byteCount(); #endif // _retData.copy(_dc.m_pImage->bits(), nLen); } while (false); return _retData; }
bool CCImage::initWithString( const char * pText, int nWidth/* = 0*/, int nHeight/* = 0*/, ETextAlign eAlignMask/* = kAlignCenter*/, const char * pFontName/* = nil*/, int nSize/* = 0*/) { bool bRet = false; do { CC_BREAK_IF(! pText); BitmapDC &dc = sharedBitmapDC(); /* init font with font name and size */ CC_BREAK_IF(! dc.setFont(pFontName, nSize)); /* compute text width and height */ if (nWidth <= 0 || nHeight <= 0) { dc.getTextExtentPoint(pText, &nWidth, &nHeight); } CC_BREAK_IF(nWidth <= 0 || nHeight <= 0); bRet = dc.drawText(pText, nWidth, nHeight, eAlignMask); /*init image information */ SkBitmap *pBitmap = dc.getBitmap(); CC_BREAK_IF(! pBitmap); int nWidth = pBitmap->width(); int nHeight = pBitmap->height(); CC_BREAK_IF(nWidth <= 0 || nHeight <= 0); int nDataLen = pBitmap->rowBytes() * pBitmap->height(); m_pData = new unsigned char[nDataLen]; CC_BREAK_IF(! m_pData); memcpy((void*) m_pData, pBitmap->getPixels(), nDataLen); m_nWidth = (short)nWidth; m_nHeight = (short)nHeight; m_bHasAlpha = true; m_bPreMulti = true; m_nBitsPerComponent = pBitmap->bytesPerPixel(); bRet = true; } while (0); return bRet; }
KDbool Image::initWithPlatformFont ( const KDchar* szText, KDint nWidth, KDint nHeight, TextAlign eAlignMask, const KDchar* szFontName, KDint nSize, KDfloat fTextTintR, KDfloat fTextTintG, KDfloat fTextTintB, KDbool bShadow, KDfloat fShadowOffsetX, KDfloat fShadowOffsetY, KDfloat fShadowOpacity, KDfloat fShadowBlur, KDbool bStroke, KDfloat fStrokeR, KDfloat fStrokeG, KDfloat fStrokeB, KDfloat fStrokeSize ) { KDbool bRet = KD_FALSE; do { CC_BREAK_IF ( !szText ); BitmapDC& tDC = sharedBitmapDC ( ); CC_BREAK_IF ( !tDC.getBitmapFromJava ( szText, nWidth, nHeight, eAlignMask, szFontName, nSize ) ); m_pData = tDC.m_pData; m_nWidth = tDC.m_nWidth; m_nHeight = tDC.m_nHeight; m_bHasPremultipliedAlpha = KD_FALSE; m_eRenderFormat = Texture2D::PixelFormat::RGBA8888; m_nDataLen = m_nWidth * m_nHeight * 4; bRet = KD_TRUE; } while ( 0 ); return bRet; }
Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha) { Data ret; do { BitmapDC &dc = sharedBitmapDC(); if(! dc.getBitmapFromJavaShadowStroke(text, (int)textDefinition._dimensions.width, (int)textDefinition._dimensions.height, align, textDefinition )) { break;}; width = dc._width; height = dc._height; ret.fastSet(dc._data,width * height * 4); hasPremultipliedAlpha = true; } while (0); return ret; }
bool CCImage::initWithString( const char * pText, int nWidth/* = 0*/, int nHeight/* = 0*/, ETextAlign eAlignMask/* = kAlignCenter*/, const char * pFontName/* = nil*/, int nSize/* = 0*/) { bool bRet = false; TUChar* pWText = NULL; do { CC_BREAK_IF(! pText); int nLen = strlen(pText) + 1; CC_BREAK_IF(! (pWText = new TUChar[nLen])); TUString::StrGBToUnicode(pWText, (Char*)pText); BitmapDC& dc = sharedBitmapDC(); dc.setFont(pFontName, nSize); TSize size(nWidth, nHeight); dc.getTextExtentPoint(pWText, nLen, size); CC_BREAK_IF(! size.Width() || ! size.Height()); // set style UInt32 styles = GUI_API_STYLE_SPECIFY_FORE_COLOR | GUI_API_STYLE_ROP_MODE_TRANSPARENT | GUI_API_STYLE_CLIP_WORDWRAP | GUI_API_STYLE_SPECIFY_BACK_COLOR | GUI_API_STYLE_SPECIFY_FONT; switch (eAlignMask) { case kAlignCenter: styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_MIDDLE; break; case kAlignTop: styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_TOP; break; case kAlignTopRight: styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_TOP; break; case kAlignRight: styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_MIDDLE; break; case kAlignBottomRight: styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_BOTTOM; break; case kAlignBottom: styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_BOTTOM; break; case kAlignBottomLeft: styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_BOTTOM; break; case kAlignLeft: styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_MIDDLE; break; case kAlignTopLeft: styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_TOP; } CC_BREAK_IF(! dc.drawText(pWText, nLen, size, styles)); // init image information TBitmap * pBitmap = dc.getBitmap(); CC_BREAK_IF(! pBitmap); INT32 nWidth = pBitmap->GetWidth(); INT32 nHeight = pBitmap->GetHeight(); CC_BREAK_IF(nWidth <= 0 || nHeight <= 0); INT32 nDataLen = pBitmap->GetRowBytes() * nHeight; m_pData.reset(new ccxByte[nDataLen]); CC_BREAK_IF(! m_pData.get()); memcpy((void*) m_pData.get(), pBitmap->GetDataPtr(), nDataLen); m_nWidth = (ccxInt16)nWidth; m_nHeight = (ccxInt16)nHeight; m_bHasAlpha = true; m_bPreMulti = true; m_nBitsPerComponent = pBitmap->GetDepth() / 4; bRet = true; } while (0); if (pWText) { delete [] pWText; pWText = NULL; } return bRet; }