const unsigned int TextShape::setSizeToFit(const int w, const int h) { fontSize = h; int textw, texth; getTextDimensions(NULL, NULL, &textw, &texth, NULL); // printf("setSizeToFit(%d, %d):\n", w, h); // printf("\ttrying %dpt...\n", fontSize); // printf("\t%s\n", txtStr); while ((textw <= w) && (texth <= h)) { fontSize++; getTextDimensions(NULL, NULL, &textw, &texth, NULL); // printf("\ttrying %dpt...\n", fontSize); // printf("\t\t(%d, %d)\n", textw, texth); } while ((textw > w) && (texth > h)) { fontSize--; getTextDimensions(NULL, NULL, &textw, &texth, NULL); // printf("\ttrying %dpt...\n", fontSize); // printf("\t\t(%d, %d)\n", textw, texth); } setFontSize(fontSize); // printf("\tsetFontSize(%d)\n", fontSize); return fontSize; }
unsigned int TextShape::makeLine(const int width) { setFontSize(28); char t[500]; strcpy(t, ""); int textw = 0; do { strcat(t, "–"); if (txtStr) { std::free(txtStr); } txtStr = strdup(t); unicodeStr = SDLGui::UTF16_fromChar(txtStr); setLabel(txtStr); getTextDimensions(NULL, NULL, &textw, NULL, NULL); } while (textw < width); // Remove the last mdash: int len = strlen(t); t[len - 7] = '\0'; setText(t); getTextDimensions(NULL, NULL, &textw, NULL, NULL); return textw; }
void TextShape::setFontSize(const unsigned int ptSize) { fontSize = ptSize; assert(fontSize > 0); assert(fontSize < MAX_TEXTSHAPE_FONTSIZE); if (textShapeFont[fontSize] == NULL) { textShapeFont[fontSize] = FONT_LoadTTF("FreeSans.ttf", fontSize); } assert(textShapeFont[fontSize] != NULL); int textw, texth, textx, texty; getTextDimensions(&textx, &texty, &textw, &texth, NULL, &baselineOffset); restore_behind(); set_noimages(textw, texth); shapePoly = poly(selectionBuffer, shapePoly); bool regen_cache = true; set_active_image(get_active_image_n(), regen_cache); display(); }
void CObjectTitle::setTitle(const std::string &title) { if(m_title != title) { m_title = title; Ogre::UTFString utfText = ConvertToUTFString(m_title); m_pTextArea->setCaption(utfText); m_textDim = getTextDimensions(utfText); m_pContainer->setDimensions(m_textDim.x, m_textDim.y); } }
void TextShape::setText(const QString& t) { update(); Q_UNUSED (t) #if 0 assert(t != NULL); if ((t[0] == '=') && isdigit(t[1])) { unsigned int value = atoi(t + 1); if ((fontSize < 1) || (fontSize > MAX_TEXTSHAPE_FONTSIZE)) { return; } fontSize = value; } else if ((t[0] == '=') && (t[1] == 'f') && isdigit(t[2])) { int fitw, fith; int numRead = sscanf(t, "=f%dx%d", &fitw, &fith); if (numRead == 2) { setSizeToFit(fitw, fith); } } else if ((t[0] == '=') && (t[1] == 'l') && isdigit(t[2])) { int fitw; int numRead = sscanf(t, "=l%d", &fitw); if (numRead == 1) { makeLine(fitw); } } else { if (txtStr) { std::free(txtStr); } txtStr = strdup(t); //QT unicodeStr = UTF16_fromChar(txtStr); setLabel(txtStr); } if (textShapeFont[fontSize] == NULL) { textShapeFont[fontSize] = FONT_LoadTTF("FreeSans.ttf", fontSize); } assert(textShapeFont[fontSize] != NULL); assert(fontSize > 0); assert(fontSize < MAX_TEXTSHAPE_FONTSIZE); int textw, texth, textx, texty; getTextDimensions(&textx, &texty, &textw, &texth, NULL, &baselineOffset); restore_behind(); set_noimages(textw, texth); shapePoly = poly(selectionBuffer, shapePoly); bool regen_cache = true; set_active_image(get_active_image_n(), regen_cache); display(); #endif }