status ws_create_font(FontObj f, DisplayObj d) { XpceFontInfo xref; DisplayWsXref r = d->ws_ref; XftFont *xft = NULL; if ( !instanceOfObject(f->x_name, ClassCharArray) || !isstrA(&f->x_name->data) ) /* HACK */ { XftPattern *p = XftPatternCreate(); XftPattern *match; FcResult fcrc; int i; char *fam; int mono = FALSE; Real scale = getClassVariableValueObject(f, NAME_scale); double fscale = (scale ? valReal(scale) : 1.0); if ( f->family == NAME_screen ) { fam = "monospace"; mono = TRUE; } else fam = strName(f->family); XftPatternAddString(p, XFT_FAMILY, fam); XftPatternAddDouble(p, XFT_PIXEL_SIZE, (double)valInt(f->points)*fscale); if ( f->style == NAME_italic ) XftPatternAddInteger(p, XFT_SLANT, XFT_SLANT_ITALIC); else if ( f->style == NAME_roman ) XftPatternAddInteger(p, XFT_SLANT, XFT_SLANT_ROMAN); else if ( f->style == NAME_bold ) XftPatternAddInteger(p, XFT_WEIGHT, XFT_WEIGHT_BOLD); if ( mono ) { DEBUG(NAME_font, Cprintf("Asking for fixed\n")); XftPatternAddInteger(p, XFT_SPACING, XFT_MONO); } if ( !(match = XftFontMatch(r->display_xref, r->screen, p, &fcrc)) ) { DEBUG(NAME_font, Cprintf("XftFontMatch() failed. Calling replaceFont()\n")); return replaceFont(f, d); } #ifdef HAVE_XFTNAMEUNPARSE DEBUG(NAME_font, { char buf[1024]; XftNameUnparse(match, buf, sizeof(buf)); Cprintf("Match = '%s'\n", buf); });
static HGLOBAL ws_string_to_global_mem(String s) { int size = s->s_size; int extra = str_count_chr(s, 0, s->s_size, '\n'); HGLOBAL mem; wchar_t *data; int i; if ( !(mem = GlobalAlloc(GMEM_MOVEABLE, (size+extra+1)*sizeof(wchar_t))) ) { Cprintf("Cannot allocate\n"); return 0; } data = GlobalLock(mem); if ( isstrA(s) ) { charA *q; for(q=s->s_textA,i=0; i<size; i++) { if ( *q == '\n' ) *data++ = '\r'; *data++ = *q++; } *data = EOS; } else { charW *q; for(q=s->s_textW,i=0; i<size; i++) { if ( *q == '\n' ) *data++ = '\r'; *data++ = *q++; } *data = EOS; } GlobalUnlock(mem); return mem; }
static ssize_t Sread_object(void *handle, char *buf, size_t size) { OpenObject h = handle; Any argv[2]; CharArray sub; int chread; size_t advance; if ( isFreedObj(h->object) ) { errno = EIO; return -1; } if ( h->encoding == ENC_WCHAR ) { advance = size/sizeof(wchar_t); } else if ( h->encoding == ENC_OCTET ) { advance = size; } else { assert(0); errno = EIO; return -1; } argv[0] = toInt(h->point); argv[1] = toInt(advance); if ( (sub = getv(h->object, NAME_readAsFile, 2, argv)) && instanceOfObject(sub, ClassCharArray) ) { String s = &sub->data; assert(s->size <= advance); if ( h->encoding == ENC_WCHAR ) { if ( isstrA(s) ) { charW *dest = (charW*)buf; const charA *f = s->s_textA; const charA *e = &f[s->size]; while(f<e) *dest++ = *f++; } else { memcpy(buf, s->s_textW, s->size*sizeof(charW)); } chread = s->size * sizeof(wchar_t); } else { if ( isstrA(s) ) { memcpy(buf, s->s_textA, s->size); } else { errno = EIO; chread = -1; } chread = s->size; } h->point += s->size; } else { errno = EIO; chread = -1; } return chread; }