wchar_t *PDFTextWordInterop::getText() { if(_textWord != NULL) { globalParams->setTextEncoding("UTF-8"); TextWord *word = (TextWord *)_textWord; GString *text = word->getText(); wchar_t *utfText = GetUTF8String(text); delete text; return utfText; } else if(_wordList != NULL) { TextWordList *wordList =(TextWordList *)_wordList; TextWord *word = wordList->get(_currentWord); if(word != NULL) { GString *text = word->getText(); wchar_t *utfText = GetUTF8String(text); // delete text; return utfText; } } return NULL; }
/** Get the width of a string. */ int GetStringWidth(FontType ft, const char *str) { #ifdef USE_XFT XGlyphInfo extents; #endif #ifdef USE_FRIBIDI FriBidiChar *temp_i; FriBidiChar *temp_o; FriBidiParType type = FRIBIDI_PAR_ON; int unicodeLength; #endif int len; char *output; int result; char *utf8String; /* Convert to UTF-8 if necessary. */ utf8String = GetUTF8String(str); /* Length of the UTF-8 string. */ len = strlen(utf8String); /* Apply the bidi algorithm if requested. */ #ifdef USE_FRIBIDI temp_i = AllocateStack((len + 1) * sizeof(FriBidiChar)); temp_o = AllocateStack((len + 1) * sizeof(FriBidiChar)); unicodeLength = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, utf8String, len, temp_i); fribidi_log2vis(temp_i, unicodeLength, &type, temp_o, NULL, NULL, NULL); output = AllocateStack(4 * len + 1); fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, temp_o, unicodeLength, (char*)output); len = strlen(output); #else output = utf8String; #endif /* Get the width of the string. */ #ifdef USE_XFT JXftTextExtentsUtf8(display, fonts[ft], (const unsigned char*)output, len, &extents); result = extents.xOff; #else result = XTextWidth(fonts[ft], output, len); #endif /* Clean up. */ #ifdef USE_FRIBIDI ReleaseStack(temp_i); ReleaseStack(temp_o); ReleaseStack(output); #endif ReleaseUTF8String(utf8String); return result; }
std::string AXLibGetWindowTitle(AXUIElementRef WindowRef) { CFStringRef WindowTitleRef = (CFStringRef) AXLibGetWindowProperty(WindowRef, kAXTitleAttribute); std::string WindowTitle; if(WindowTitleRef) { WindowTitle = GetUTF8String(WindowTitleRef); if(WindowTitle.empty()) WindowTitle = CFStringGetCStringPtr(WindowTitleRef, kCFStringEncodingMacRoman); CFRelease(WindowTitleRef); } return WindowTitle; }
/** Display a string. */ void RenderString(Drawable d, FontType font, ColorType color, int x, int y, int width, const char *str) { #ifdef USE_ICONV static char isUTF8 = -1; #endif XRectangle rect; Region renderRegion; int len; char *output; #ifdef USE_FRIBIDI FriBidiChar *temp_i; FriBidiChar *temp_o; FriBidiParType type = FRIBIDI_PAR_ON; int unicodeLength; #endif #ifdef USE_XFT XGlyphInfo extents; #endif char *utf8String; /* Early return for empty strings. */ if(!str || !str[0]) { return; } /* Convert to UTF-8 if necessary. */ utf8String = GetUTF8String(str); /* Get the length of the UTF-8 string. */ len = strlen(utf8String); /* Apply the bidi algorithm if requested. */ #ifdef USE_FRIBIDI temp_i = AllocateStack((len + 1) * sizeof(FriBidiChar)); temp_o = AllocateStack((len + 1) * sizeof(FriBidiChar)); unicodeLength = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, utf8String, len, temp_i); fribidi_log2vis(temp_i, unicodeLength, &type, temp_o, NULL, NULL, NULL); output = AllocateStack(4 * len + 1); fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, temp_o, unicodeLength, (char*)output); len = strlen(output); #else output = utf8String; #endif /* Get the bounds for the string based on the specified width. */ rect.x = x; rect.y = y; rect.height = GetStringHeight(font); #ifdef USE_XFT JXftTextExtentsUtf8(display, fonts[font], (const unsigned char*)output, len, &extents); rect.width = extents.xOff; #else rect.width = XTextWidth(fonts[font], output, len); #endif rect.width = Min(rect.width, width) + 2; /* Combine the width bounds with the region to use. */ renderRegion = XCreateRegion(); XUnionRectWithRegion(&rect, renderRegion, renderRegion); /* Display the string. */ #ifdef USE_XFT JXftDrawChange(xd, d); JXftDrawSetClip(xd, renderRegion); JXftDrawStringUtf8(xd, GetXftColor(color), fonts[font], x, y + fonts[font]->ascent, (const unsigned char*)output, len); JXftDrawChange(xd, rootWindow); #else JXSetForeground(display, fontGC, colors[color]); JXSetRegion(display, fontGC, renderRegion); JXSetFont(display, fontGC, fonts[font]->fid); JXDrawString(display, d, fontGC, x, y + fonts[font]->ascent, output, len); #endif /* Free any memory used for UTF conversion. */ #ifdef USE_FRIBIDI ReleaseStack(temp_i); ReleaseStack(temp_o); ReleaseStack(output); #endif ReleaseUTF8String(utf8String); XDestroyRegion(renderRegion); }
float CFont::GetStringWidth(const std::string& text) { return GetStringWidth( GetUTF8String( text ) ); }
void CFont::DrawString(const std::string& text, const Rectf& bounds, bool overflowX /*= false*/) { ustring str = GetUTF8String( text ); Vect2f screenSz = m_gui->m_screen.size; Vect2f pos = bounds.position; pos.x = GetLineStartXPosition(str, bounds, 0); CEffectManager::m_SceneParameters.m_BaseColor = m_color; auto technique = m_material->getRenderableObjectTechique()->GetEffectTechnique(); m_material->apply(); m_pages[0]->Activate(0); for ( int b = 0; b < str.length(); b += MAX_GLYPHS_BATCH ) { m_glyphs.clear(); uchar lastChar = -1; for ( int i = b; (i - b < MAX_GLYPHS_BATCH) && (i < str.length()); ++i ) { uchar c = str[i]; if (c == '\n') { lastChar = -1; pos.x = GetLineStartXPosition(str, bounds, i+1); pos.y += m_lineHeight; continue; } auto descIt = m_chars.find( c ); if ( descIt == m_chars.end() ) { c = -1; descIt = m_chars.find( -1 ); } if ( lastChar == -1 ) { auto kernIt = m_kernings.find( std::make_pair( lastChar, c ) ); if ( kernIt != m_kernings.end() ) { pos.x += kernIt->second; } } auto & desc = descIt->second; Rectf charR( pos, desc.size ); charR.position += desc.offset; charR.x /= screenSz.x; charR.y /= screenSz.y; charR.w /= screenSz.x; charR.h /= screenSz.y; m_glyphs.push_back( {Vect4f(charR.x, charR.y, charR.w, charR.h), desc.uvRect.position, desc.uvRect.size } ); pos.x += desc.xAdvance; lastChar = c; } m_glyphsVtxs->UpdateVertices(m_gui->m_contextManager->GetDeviceContext(), m_glyphs.data(), m_glyphs.size()); m_glyphsVtxs->Render(m_gui->m_contextManager, technique); } }