int TkpMeasureCharsInContext( Tk_Font tkfont, CONST char *source, int numBytes, int rangeStart, int rangeLength, int maxLength, int flags, int *lengthPtr) { (void) numBytes; /*unused*/ return Tk_MeasureChars(tkfont, source + rangeStart, rangeLength, maxLength, flags, lengthPtr); }
/* ** Given a Block and an x coordinate, find the Index of the character ** that is closest to the given x coordinate. ** ** The x-coordinate might specify a point to the left of the block, ** in which case the procedure returns the first token and a character ** index of 0. Or the x-coordinate might specify a point to the right ** of the block, in which case the last token is returned with an index ** equal to its last character. */ static void FindIndexInBlock( HtmlWidget *htmlPtr, /* The widget */ HtmlBlock *pBlock, /* The block */ int x, /* The x coordinate */ HtmlElement **ppToken, /* Write the closest token here */ int *pIndex /* Write the charater index in ppToken here */ ){ HtmlElement *p; Tk_Font font; int len; int n; p = pBlock->base.pNext; HtmlLock(htmlPtr); font = HtmlGetFont(htmlPtr, p->base.style.font); if( HtmlUnlock(htmlPtr) ){ *ppToken = p; *pIndex = 0; return; } if( x <= pBlock->left ){ *ppToken = p; *pIndex = 0; TestPoint(0); return; }else if( x>= pBlock->right ){ *ppToken = p; *pIndex = 0; while( p && p->base.type!=Html_Block ){ *ppToken = p; p = p->base.pNext; TestPoint(0); } p = *ppToken; if( p && p->base.type==Html_Text ){ *pIndex = p->base.count - 1; TestPoint(0); }else{ TestPoint(0); } return; } if( pBlock->n==0 ){ *ppToken = p; *pIndex = 0; TestPoint(0); }else{ TestPoint(0); } n = Tk_MeasureChars(font, pBlock->z, pBlock->n, x - pBlock->left, 0, &len); *pIndex = 0; *ppToken = 0; while( p && n>=0 ){ switch( p->base.type ){ case Html_Text: if( n<p->base.count ){ *pIndex = n; TestPoint(0); }else{ *pIndex = p->base.count - 1; TestPoint(0); } *ppToken = p; n -= p->base.count; break; case Html_Space: if( p->base.style.flags & STY_Preformatted ){ if( n<p->base.count ){ *pIndex = n; TestPoint(0); }else{ *pIndex = p->base.count - 1; TestPoint(0); } *ppToken = p; n -= p->base.count; }else{ *pIndex = 0; *ppToken = p; n--; TestPoint(0); } break; default: TestPoint(0); break; } if( p ){ p = p->base.pNext; TestPoint(0); }else{ TestPoint(0); } } }
static UnixFtFont * InitFont( Tk_Window tkwin, FcPattern *pattern, UnixFtFont *fontPtr) { FcFontSet *set; FcCharSet *charset; FcResult result; XftFont *ftFont; int i, iWidth; if (!fontPtr) { fontPtr = ckalloc(sizeof(UnixFtFont)); } FcConfigSubstitute(0, pattern, FcMatchPattern); XftDefaultSubstitute(Tk_Display(tkwin), Tk_ScreenNumber(tkwin), pattern); /* * Generate the list of fonts */ set = FcFontSort(0, pattern, FcTrue, NULL, &result); if (!set) { ckfree(fontPtr); return NULL; } fontPtr->fontset = set; fontPtr->pattern = pattern; fontPtr->faces = ckalloc(set->nfont * sizeof(UnixFtFace)); fontPtr->nfaces = set->nfont; /* * Fill in information about each returned font */ for (i = 0; i < set->nfont; i++) { fontPtr->faces[i].ftFont = 0; fontPtr->faces[i].ft0Font = 0; fontPtr->faces[i].source = set->fonts[i]; if (FcPatternGetCharSet(set->fonts[i], FC_CHARSET, 0, &charset) == FcResultMatch) { fontPtr->faces[i].charset = FcCharSetCopy(charset); } else { fontPtr->faces[i].charset = 0; } fontPtr->faces[i].angle = 0.0; } fontPtr->display = Tk_Display(tkwin); fontPtr->screen = Tk_ScreenNumber(tkwin); fontPtr->ftDraw = 0; fontPtr->color.color.red = 0; fontPtr->color.color.green = 0; fontPtr->color.color.blue = 0; fontPtr->color.color.alpha = 0xffff; fontPtr->color.pixel = 0xffffffff; /* * Fill in platform-specific fields of TkFont. */ ftFont = GetFont(fontPtr, 0, 0.0); fontPtr->font.fid = XLoadFont(Tk_Display(tkwin), "fixed"); GetTkFontAttributes(ftFont, &fontPtr->font.fa); GetTkFontMetrics(ftFont, &fontPtr->font.fm); /* * Fontconfig can't report any information about the position or thickness * of underlines or overstrikes. Thus, we use some defaults that are * hacked around from backup defaults in tkUnixFont.c, which are in turn * based on recommendations in the X manual. The comments from that file * leading to these computations were: * * If the XA_UNDERLINE_POSITION property does not exist, the X manual * recommends using half the descent. * * If the XA_UNDERLINE_THICKNESS property does not exist, the X * manual recommends using the width of the stem on a capital letter. * I don't know of a way to get the stem width of a letter, so guess * and use 1/3 the width of a capital I. * * Note that nothing corresponding to *either* property is reported by * Fontconfig at all. [Bug 1961455] */ { TkFont *fPtr = &fontPtr->font; fPtr->underlinePos = fPtr->fm.descent / 2; Tk_MeasureChars((Tk_Font) fPtr, "I", 1, -1, 0, &iWidth); fPtr->underlineHeight = iWidth / 3; if (fPtr->underlineHeight == 0) { fPtr->underlineHeight = 1; } if (fPtr->underlineHeight + fPtr->underlinePos > fPtr->fm.descent) { fPtr->underlineHeight = fPtr->fm.descent - fPtr->underlinePos; if (fPtr->underlineHeight == 0) { fPtr->underlinePos--; fPtr->underlineHeight = 1; } } } return fontPtr; }