Ejemplo n.º 1
0
std::vector<KFontProperties::GlyphRange> getRanges(const TTF_Font *_Font) {
  std::vector<KFontProperties::GlyphRange> ranges;
  // find glyph ranges.
  int ch = 0;
  while(ch < 0x10000) {
    if(TTF_GlyphIsProvided(_Font, ch++)) {
      int rs = ch - 1;
      while(TTF_GlyphIsProvided(_Font, ch++)) {
      }
      ranges.push_back(KFontProperties::GlyphRange(rs, ch - 2));
    }
  }
  return ranges;
}
Ejemplo n.º 2
0
TTF_Font* FontAdapter_SDL_ttf::FindFontForCharacter(const std::string& character) const
{
	std::wstring_convert<std::codecvt_utf8<wchar_t>> conv(".", L".");
	auto result = conv.from_bytes(character);
	if (!result.empty())
	{
		if (_emoji && TTF_GlyphIsProvided(_emoji, result[0]))
			return _emoji;

		if (_font1 && TTF_GlyphIsProvided(_font1, result[0]))
			return _font1;
	}

	return _font2;
}
Ejemplo n.º 3
0
		int LOBJECT_METHOD(isGlyphProvided, TTF_Font * font){
			if (state.is_number(1)){
				Uint16 glyph = static_cast<Uint16>(state.to_integer(1));
				int result = TTF_GlyphIsProvided(font, glyph);
				state.push_integer(result);
				return 1;
			}
			return 0;
		}
Ejemplo n.º 4
0
int getFirstGlyph(const TTF_Font *_Font) {
  int ch = 0;
  while(ch < 0x10000) {
    if(TTF_GlyphIsProvided(_Font, ch)) {
      return ch;
    }
    ch++;
  }
}
Ejemplo n.º 5
0
void load_font(char *fname, int size)
{
    char *p;

    free_font();
    font=TTF_OpenFont(fname, size);
    if(!font)
    {
        printf("TTF_OpenFont: %s\n", TTF_GetError());
        exit(3);
    }

    /* print some metrics and attributes */
    printf("size                    : %d\n",size);
    printf("TTF_FontHeight          : %d\n",TTF_FontHeight(font));
    printf("TTF_FontAscent          : %d\n",TTF_FontAscent(font));
    printf("TTF_FontDescent         : %d\n",TTF_FontDescent(font));
    printf("TTF_FontLineSkip        : %d\n",TTF_FontLineSkip(font));
    printf("TTF_FontFaceIsFixedWidth: %d\n",TTF_FontFaceIsFixedWidth(font));
    {
        char *str=TTF_FontFaceFamilyName(font);
        if(!str)
            str="(null)";
        printf("TTF_FontFaceFamilyName  : \"%s\"\n",str);
    }
    {
        char *str=TTF_FontFaceStyleName(font);
        if(!str)
            str="(null)";
        printf("TTF_FontFaceStyleName   : \"%s\"\n",str);
    }
    if(TTF_GlyphIsProvided(font,'g'))
    {
        int minx, maxx, miny, maxy, advance;
        TTF_GlyphMetrics(font,'g', &minx, &maxx, &miny, &maxy, &advance);
        printf("TTF_GlyphMetrics('g'):\n\tminx=%d\n\tmaxx=%d\n\tminy=%d\n\tmaxy=%d\n\tadvance=%d\n",
            minx, maxx, miny, maxy, advance);
    }
    else
        printf("TTF_GlyphMetrics('g'): unavailable in font!\n");

    /* set window title and icon name, using filename and stuff */
    p=strrchr(fname,'/');
    if(!p)
        p=strrchr(fname,'\\');
    if(!p)
        p=strrchr(fname,':');
    if(!p)
        p=fname;
    else
        p++;

    /* cache new glyphs */
    cache_glyphs();
}
Ejemplo n.º 6
0
int getTotalGlyphs(const TTF_Font *_Font) {
  int total = 0;
  int ch = 0;
  while(ch < 0x10000) {
    if(TTF_GlyphIsProvided(_Font, ch)) {
      total++;
    }
    ch++;
  }
  return total;
}
Ejemplo n.º 7
0
int getLastGlyph(const TTF_Font *_Font) {
  int last = 0;
  int ch = 0;
  while(ch < 0x10000) {
    if(TTF_GlyphIsProvided(_Font, ch)) {
      last = ch;
    }
    ch++;
  }
  return last;
}
Ejemplo n.º 8
0
static mrb_value
mrb_sdl2_ttf_font_get_glyph_index(mrb_state *mrb, mrb_value self)
{
  mrb_value character;
  Uint16 ch;
  mrb_get_args(mrb, "b", &character);
  if (mrb_obj_is_kind_of(mrb, character, mrb_class_get_under(mrb, mrb->object_class, "String"))) {
    ch = *RSTRING_PTR(character);
  } else if (mrb_obj_is_kind_of(mrb, character, mrb_class_get_under(mrb, mrb->object_class, "Integer"))) {
    ch = (Uint16) character.value.i;
  }
  return mrb_fixnum_value(TTF_GlyphIsProvided(mrb_sdl2_font_get_ptr(mrb, self), ch));
}
Ejemplo n.º 9
0
bool font_supports_string_ttf(const utf8 *text, int fontSize)
{
    const utf8 *src = text;
    const TTF_Font *font = gCurrentTTFFontSet->size[fontSize].font;

    uint32 codepoint;
    while ((codepoint = utf8_get_next(src, &src)) != 0) {
        bool supported = TTF_GlyphIsProvided(font, (uint16)codepoint);
        if (!supported) {
            return false;
        }
    }
    return true;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
boolType SDLFont::hasGlyph(Uint16 ch) {
    int isProvided = TTF_GlyphIsProvided(this->fontContext, ch);
    return (isProvided > 0) ? true : false;
}