#include "./FreeType/ft2build.h"
#include FT_FREETYPE_H
#pragma comment(lib, "./FreeType/freetype248.lib")
int main() {
FT_Library library;
FT_Face face1;
FT_Face face2;
const char *filename = "C:\\Windows\\Fonts\\Arial.ttf"; /* the algorithm should not be font specific, i.e., suitable for a variety of fonts */
int fontSize1 = 40; /* fontSize1 is a given value */
int fontSize2; /* fontSize2 need to be calculated, derived from fontSize1 */
FT_Size_RequestRec rq;
FT_Init_FreeType(&library);
FT_New_Face(library, filename, 0, &face1);
FT_New_Face(library, filename, 0, &face2);
/* set the REAL_DIM size, fontSize1 */
rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM;
rq.width = 0;
rq.height = fontSize1 << 6;
rq.horiResolution = 0;
rq.vertResolution = 0;
FT_Request_Size(face1, &rq);
/* set the NOMINAL size, fontSize2 */
fontSize2 = fontSize1 - 4; /* How to calculate fontSize2 to meet the following requirements? I tried to -1, -2, -3, and finally found -4 is good */
FT_Set_Char_Size(face2, 0, fontSize2 << 6, 0, 0);
/* the requirement for the calculation of fontSize2 is, for example */
if (face2->size->metrics.ascender == face1->size->metrics.ascender && face2->size->metrics.descender == face1->size->metrics.descender) {
printf("Good, fontSize2 is just what we wanted!\n");
printf("ascender1=%i\tascneder2=%i\ndescender1=%i\tdescender2=%i\n", face1->size->metrics.ascender, face2->size->metrics.ascender, face1->size->metrics.descender, face1->size->metrics.descender);
} else {
printf("Bad, try another fontSize2.\n");
printf("ascender1=%i\tascneder2=%i\ndescender1=%i\tdescender2=%i\n", face1->size->metrics.ascender, face2->size->metrics.ascender, face1->size->metrics.descender, face1->size->metrics.descender);
}
/* clean up */
FT_Done_Face(face1);
FT_Done_Face(face2);
FT_Done_FreeType(library);
return 0;
}
On Fri, Mar 2, 2012 at 2:04 AM, Werner LEMBERG
<address@hidden> wrote:
> I am facing a problem which requires the calculation of the
> equivalent font size (fontSize2) for FT_SIZE_REQUEST_TYPE_NOMINAL,
> [...]
Answering your question would be much simpler if you provided a
(compilable) code snippet which demonstrates what you expect and what
you get instead, ideally using a freely available font.
Werner