Bool renderText(GPU_Target* renderTarget, GC gc, int x, int y, const char* string) { LOG("Rendering text: '%s'\n", string); if (string == NULL || string[0] == '\0') { return True; } GraphicContext* gContext = GET_GC(gc); SDL_Color color = { GET_RED_FROM_COLOR(gContext->foreground), GET_GREEN_FROM_COLOR(gContext->foreground), GET_BLUE_FROM_COLOR(gContext->foreground), GET_ALPHA_FROM_COLOR(gContext->foreground), }; SDL_Surface* fontSurface = TTF_RenderUTF8_Blended(GET_FONT(gContext->font), string, color); if (fontSurface == NULL) { return False; } GPU_Image* fontImage = GPU_CopyImageFromSurface(fontSurface); SDL_FreeSurface(fontSurface); if (fontImage == NULL) { return False; } y -= TTF_FontAscent(GET_FONT(gContext->font)); GPU_Blit(fontImage, NULL, renderTarget, x + fontImage->w / 2, y + fontImage->h / 2); GPU_FreeImage(fontImage); GPU_Flip(renderTarget); return True; }
// This function goes through all strings in the list to find the width, // in pixels, of the longest string in the list. void AwtList::UpdateMaxItemWidth() { m_nMaxWidth = 0; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(2) < 0) return; HDC hDC = ::GetDC(GetHWnd()); jobject self = GetPeer(env); DASSERT(self); /* target is java.awt.List */ jobject target = env->GetObjectField(self, AwtObject::targetID); jobject font = GET_FONT(target, self); int nCount = GetCount(); for ( int i=0; i < nCount; i++ ) { jstring jstr = GetItemString( env, target, i ); SIZE size = AwtFont::getMFStringSize( hDC, font, jstr ); if ( size.cx > m_nMaxWidth ) m_nMaxWidth = size.cx; env->DeleteLocalRef( jstr ); } // free up the shared DC and release local refs ::ReleaseDC(GetHWnd(), hDC); env->DeleteLocalRef( target ); env->DeleteLocalRef( font ); // Now adjust the horizontal scrollbar extent AdjustHorizontalScrollbar(); }
int getTextWidth(XFontStruct* font_struct, const char* string) { int width, height; if (TTF_SizeUTF8(GET_FONT(font_struct->fid), string, &width, &height) != 0) { LOG("Failed to calculate the text with in XTextWidth[16]: %s! " "Returning max width of font.\n", TTF_GetError()); return (int) (font_struct->max_bounds.rbearing * strlen(string)); } return width; }
void AwtLabel::DoPaint(HDC hDC, RECT& r) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0 && m_peerObject != NULL && m_callbacksEnabled) { if (env->EnsureLocalCapacity(3) < 0) return; long x,y; SIZE size; /* self is sun.awt.windows.WLabelPeer */ jobject self = GetPeer(env); DASSERT(self); /* target is java.awt.Label */ jobject target = env->GetObjectField(self, AwtObject::targetID); jobject font = GET_FONT(target, self); jstring text = (jstring)env->GetObjectField(target, AwtLabel::textID); size = AwtFont::getMFStringSize(hDC, font, text); ::SetTextColor(hDC, GetColor()); /* Redraw whole label to eliminate display noise during resizing. */ VERIFY(::GetClientRect(GetHWnd(), &r)); VERIFY(::FillRect (hDC, &r, GetBackgroundBrush())); y = (r.top + r.bottom - size.cy) / 2; jint alignment = env->GetIntField(target, AwtLabel::alignmentID); switch (alignment) { case java_awt_Label_CENTER: x = (r.left + r.right - size.cx) / 2; break; case java_awt_Label_RIGHT: x = r.right - 2 - size.cx; break; case java_awt_Label_LEFT: default: x = r.left + 2; break; } /* draw string */ if (isEnabled()) { AwtComponent::DrawWindowText(hDC, font, text, x, y); } else { AwtComponent::DrawGrayText(hDC, font, text, x, y); } DoCallback("handlePaint", "(IIII)V", r.left, r.top, r.right-r.left, r.bottom-r.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(text); } }
int pdf_dev_get_font_wmode (int font_id) { struct dev_font *font; font = GET_FONT(font_id); if (font) { return font->wmode; } return 0; }
double pdf_dev_get_font_ptsize (int font_id) { struct dev_font *font; font = GET_FONT(font_id); if (font) { return font->sptsize * dev_unit.dvi2pts; } return 1.0; }
int XFreeFont(Display* display, XFontStruct* font_struct) { // https://tronche.com/gui/x/xlib/graphics/font-metrics/XFreeFont.html SET_X_SERVER_REQUEST(display, X_CloseFont); TTF_CloseFont(GET_FONT(font_struct->fid)); FREE_XID(font_struct->fid); if (font_struct->per_char != NULL) { int numChars = font_struct->max_char_or_byte2 - font_struct->min_char_or_byte2; int i; for (i = 0; i < numChars; i++) { free(font_struct->per_char + i * sizeof(XCharStruct)); } } free(font_struct); return 1; }
Bool XGetFontProperty(XFontStruct* font_struct, Atom atom, unsigned long* value_return) { // https://tronche.com/gui/x/xlib/graphics/font-metrics/XGetFontProperty.html Bool res = False; char* name; switch (atom) { case XA_FONT: name = getFontXLFDName(GET_FONT(font_struct->fid)); if (name != NULL) { *value_return = (unsigned long) internalInternAtom(name); res = True; } break; default: LOG("%s: Got unknown atom %lu!\n", __func__, atom); } // Can't provide values for XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS return res; }
Score::Score(eScores scoreType, uint32 baseValue = 0) : m_scoreType(scoreType), m_text(nullptr), m_valueText(nullptr) { const uint16 fontSize = sGame->GetWindow()->getSize().x / 40; sf::Font const& font = *GET_FONT(eResources::Font_Dejavu); std::string textStr = "???"; switch (scoreType) { case eScores::PLAYER: textStr = "Player size: "; break; case eScores::GOOD_BUBBLES: textStr = "Good bubbles: "; break; } m_text = new sf::Text(textStr, font, fontSize); m_valueText = new sf::Text(std::to_string(baseValue), font, fontSize); }
char * texpdf_get_font_usedchars (int font_id) { pdf_font *font; CHECK_ID(font_id); font = GET_FONT(font_id); if (font->subtype == PDF_FONT_FONTTYPE_TYPE0) { Type0Font *t0font; t0font = Type0Font_cache_get(font->font_id); return Type0Font_get_usedchars(t0font); } else { if (!font->usedchars) { font->usedchars = NEW(256, char); memset(font->usedchars, 0, 256 * sizeof(char)); } return font->usedchars; }
pdf_obj * texpdf_get_font_reference (int font_id) { pdf_font *font; CHECK_ID(font_id); font = GET_FONT(font_id); if (font->subtype == PDF_FONT_FONTTYPE_TYPE0) { Type0Font *t0font; t0font = Type0Font_cache_get(font->font_id); return Type0Font_get_resource(t0font); } else { if (!font->reference) { font->reference = texpdf_ref_obj(pdf_font_get_resource(font)); } } return texpdf_link_obj(font->reference); }
XFontStruct* XLoadQueryFont(Display* display, _Xconst char* name) { // https://tronche.com/gui/x/xlib/graphics/font-metrics/XLoadQueryFont.html Font fontId = XLoadFont(display, name); if (fontId == None) { return NULL; } TTF_Font* font = GET_FONT(fontId); SET_X_SERVER_REQUEST(display, X_QueryFont); XFontStruct* fontStruct = malloc(sizeof(XFontStruct)); if (fontStruct == NULL) { handleOutOfMemory(0, display, 0, 0); TTF_CloseFont(font); return NULL; } fontStruct->fid = fontId; fontStruct->ascent = TTF_FontAscent(font); fontStruct->descent = abs(TTF_FontDescent(font)); fontStruct->per_char = NULL; unsigned int numChars = 0; unsigned int i; for (i = 0; i < 65536 /* 2^16 */; i++) { if (TTF_GlyphIsProvided(font, (Uint16) i)) { if (numChars == 0) { fontStruct->min_char_or_byte2 = i; } fontStruct->max_char_or_byte2 = i; numChars++; } } // if (numChars >= 256) { // fontStruct->min_byte1 = fontStruct->min_char_or_byte2 / 256; // fontStruct->max_byte1 = fontStruct->max_char_or_byte2 / 256; // fontStruct->min_char_or_byte2 = 0; // } else { fontStruct->min_byte1 = 0; fontStruct->max_byte1 = 0; // } // TODO: This is debugging fontStruct->max_char_or_byte2 = 255; // Build per_char int monospace = TTF_FontFaceIsFixedWidth(font); XCharStruct charStruct; if (!monospace) { fontStruct->per_char = malloc(sizeof(XCharStruct) * numChars); if (fontStruct->per_char == NULL) { handleOutOfMemory(0, display, 0, 0); XFreeFont(display, fontStruct); return NULL; } charStruct = fontStruct->per_char[0]; } if (fillXCharStruct(font, fontStruct->min_char_or_byte2, &charStruct) == False) { XFreeFont(display, fontStruct); return NULL; } fontStruct->max_bounds = charStruct; fontStruct->min_bounds = charStruct; if (monospace) { fontStruct->per_char = NULL; } else { int counter = 1; for (i = fontStruct->min_char_or_byte2 + 1; i < 65536 /* 2^16 */; ++i) { if (TTF_GlyphIsProvided(font, (Uint16) i)) { charStruct = fontStruct->per_char[counter]; if (fillXCharStruct(font, i, &charStruct) == False) { XFreeFont(display, fontStruct); return NULL; } // I think rbearing (aka. advance) is the value that matters here if (fontStruct->max_bounds.rbearing < charStruct.rbearing) { fontStruct->max_bounds = charStruct; } else if (fontStruct->min_bounds.rbearing > charStruct.rbearing) { fontStruct->max_bounds = charStruct; } counter++; } } } return fontStruct; }
MsgRouting AwtCheckbox::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return mrConsume; } jobject self = GetPeer(env); jobject target = env->GetObjectField(self, AwtObject::targetID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; int checkSize; UINT nState; SIZE size; jobject font = GET_FONT(target, self); jstring str = (jstring)env->GetObjectField(target, AwtCheckbox::labelID); size = AwtFont::getMFStringSize(hDC, font, str); jobject group = env->GetObjectField(target, AwtCheckbox::groupID); if (group != NULL) nState = DFCS_BUTTONRADIO; else nState = DFCS_BUTTONCHECK; if (GetState()) nState |= DFCS_CHECKED; else nState &= ~DFCS_CHECKED; if (drawInfo.itemState & ODS_SELECTED) nState |= DFCS_PUSHED; if (drawInfo.itemAction & ODA_DRAWENTIRE) { VERIFY(::FillRect (hDC, &rect, GetBackgroundBrush())); } /* draw check mark */ checkSize = GetCheckSize(); RECT boxRect; boxRect.left = (GetRTL()) ? rect.right - checkSize : rect.left; boxRect.top = (rect.bottom - rect.top - checkSize)/2; boxRect.right = boxRect.left + checkSize; boxRect.bottom = boxRect.top + checkSize; ::DrawFrameControl(hDC, &boxRect, DFC_BUTTON, nState); /* * draw string * * 4 is a heuristic number */ rect.left = rect.left + checkSize + checkSize/4; if (drawInfo.itemAction & ODA_DRAWENTIRE) { BOOL bEnabled = isEnabled(); int x = (GetRTL()) ? rect.right - (checkSize + checkSize / 4 + size.cx) : rect.left; int y = (rect.top + rect.bottom - size.cy) / 2; if (bEnabled) { AwtComponent::DrawWindowText(hDC, font, str, x, y); } else { AwtComponent::DrawGrayText(hDC, font, str, x, y); } } /* Draw focus rect */ RECT focusRect; const int margin = 2; /* 2 is a heuristic number */ focusRect.left = (GetRTL()) ? rect.right - checkSize - checkSize / 4 - 2 * margin - size.cx : rect.left - margin; focusRect.top = (rect.top+rect.bottom-size.cy)/2; focusRect.right = (GetRTL()) ? rect.right - checkSize - checkSize / 4 + margin : focusRect.left + size.cx + 2 * margin; focusRect.bottom = focusRect.top + size.cy; /* draw focus rect */ if ((drawInfo.itemState & ODS_FOCUS) && ((drawInfo.itemAction & ODA_FOCUS)|| (drawInfo.itemAction &ODA_DRAWENTIRE))) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* erase focus rect */ else if (!(drawInfo.itemState & ODS_FOCUS) && (drawInfo.itemAction & ODA_FOCUS)) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* Notify any subclasses */ rect = drawInfo.rcItem; DoCallback("handlePaint", "(IIII)V", rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(str); env->DeleteLocalRef(group); return mrConsume; }
static int dev_set_font (int font_id) { struct dev_font *font; struct dev_font *real_font; int text_rotate; double font_scale; int len; int vert_dir, vert_font; /* text_mode() must come before text_state.is_mb is changed. */ text_mode(); font = GET_FONT(font_id); ASSERT(font); /* Caller should check font_id. */ if (font->real_font_index >= 0) real_font = GET_FONT(font->real_font_index); else real_font = font; text_state.is_mb = (font->format == PDF_FONTTYPE_COMPOSITE) ? 1 : 0; vert_font = font->wmode ? 1 : 0; if (dev_param.autorotate) { vert_dir = text_state.dir_mode; } else { vert_dir = vert_font; } text_rotate = (vert_font << 2)|vert_dir; if (font->slant != text_state.matrix.slant || font->extend != text_state.matrix.extend || ANGLE_CHANGES(text_rotate, text_state.matrix.rotate)) { text_state.force_reset = 1; } text_state.matrix.slant = font->slant; text_state.matrix.extend = font->extend; text_state.matrix.rotate = text_rotate; if (!real_font->resource) { real_font->resource = pdf_get_font_reference(real_font->font_id); real_font->used_chars = pdf_get_font_usedchars(real_font->font_id); } if (!real_font->used_on_this_page) { pdf_doc_add_page_resource("Font", real_font->short_name, pdf_link_obj(real_font->resource)); real_font->used_on_this_page = 1; } font_scale = (double) font->sptsize * dev_unit.dvi2pts; len = sprintf(format_buffer, " /%s", real_font->short_name); /* space not necessary. */ format_buffer[len++] = ' '; len += p_dtoa(font_scale, MIN(dev_unit.precision+1, DEV_PRECISION_MAX), format_buffer+len); format_buffer[len++] = ' '; format_buffer[len++] = 'T'; format_buffer[len++] = 'f'; pdf_doc_add_page_content(format_buffer, len); /* op: Tf */ if (font->bold > 0.0 || font->bold != text_state.bold_param) { if (font->bold <= 0.0) len = sprintf(format_buffer, " 0 Tr"); else len = sprintf(format_buffer, " 2 Tr %.6f w", font->bold); /* _FIXME_ */ pdf_doc_add_page_content(format_buffer, len); /* op: Tr w */ } text_state.bold_param = font->bold; text_state.font_id = font_id; return 0; }
MsgRouting AwtCheckbox::WmDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT far& drawInfo) { JNIEnv *env; /* associate JNIEnv with the current thread */ if (JVM -> AttachCurrentThread((void**) &env, 0) != 0) { return mrDoDefault; // CHECK: is this the right return type?? } CriticalSection::Lock l(GetLock()); jobject self = GetPeer(); jobject target = env -> GetObjectField(self, WCachedIDs.PPCObjectPeer_targetFID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; int checkSize; UINT nState; SIZE size; jobject hJavaFont; jstring hJavaString; hJavaFont = GET_FONT(target); hJavaString = (jstring)env->CallObjectMethod(target, WCachedIDs.java_awt_Checkbox_getLabelMID); size = AwtFont::getMFStringSize(hDC,hJavaFont,hJavaString); if (env->CallObjectMethod(target, WCachedIDs.java_awt_Checkbox_getCheckboxGroupMID) != NULL) nState = DFCS_BUTTONRADIO; else nState = DFCS_BUTTONCHECK; if (GetState()) nState |= DFCS_CHECKED; else nState &= ~DFCS_CHECKED; if (drawInfo.itemState & ODS_SELECTED) nState |= DFCS_PUSHED; if (drawInfo.itemAction & ODA_DRAWENTIRE) { VERIFY(::FillRect (hDC, &rect, GetBackgroundBrush())); } //draw check mark checkSize = GetCheckSize(); RECT boxRect; boxRect.left = rect.left; boxRect.top = (rect.bottom - rect.top - checkSize)/2; boxRect.right = boxRect.left + checkSize; boxRect.bottom = boxRect.top + checkSize; ::DrawFrameControl(hDC, &boxRect, DFC_BUTTON, nState); //draw string rect.left = rect.left + checkSize + checkSize/4; //4 is a heuristic number if (drawInfo.itemAction & ODA_DRAWENTIRE) { BOOL bEnabled = isEnabled(); int x = rect.left; int y = (rect.top+rect.bottom-size.cy)/2; if (bEnabled) { AwtComponent::DrawWindowText(hDC, hJavaFont, hJavaString, x, y); } else { AwtComponent::DrawGrayText(hDC, hJavaFont, hJavaString, x, y); } } //Draw focus rect RECT focusRect; const int margin = 2; // 2 is a heuristic number focusRect.left = rect.left - margin; focusRect.top = (rect.top+rect.bottom-size.cy)/2; focusRect.right = focusRect.left + size.cx + 2*margin; focusRect.bottom = focusRect.top + size.cy; // draw focus rect if ((drawInfo.itemState & ODS_FOCUS) && ((drawInfo.itemAction & ODA_FOCUS)|| (drawInfo.itemAction &ODA_DRAWENTIRE))) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } // erase focus rect else if (!(drawInfo.itemState & ODS_FOCUS) && (drawInfo.itemAction & ODA_FOCUS)) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } // Notify any subclasses rect = drawInfo.rcItem; env -> CallVoidMethod(GetPeer(), WCachedIDs.PPCComponentPeer_handlePaintMID, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top); return mrConsume; }