69#define FONT_UNDERLINE 4
70#define FONT_OVERSTRIKE 5
71#define FONT_NUMFIELDS 6
80#define XLFD_SETWIDTH 4
81#define XLFD_ADD_STYLE 5
82#define XLFD_PIXEL_SIZE 6
83#define XLFD_POINT_SIZE 7
84#define XLFD_RESOLUTION_X 8
85#define XLFD_RESOLUTION_Y 9
86#define XLFD_SPACING 10
87#define XLFD_AVERAGE_WIDTH 11
88#define XLFD_REGISTRY 12
89#define XLFD_ENCODING 13
90#define XLFD_NUMFIELDS 14
264 0, 0, 0, 0, 0, 0, 0,
'a',
'b',
't',
'n',
'v',
'f',
'r', 0
286 Error(
"GetFontMetrics",
"argument may not be 0");
291 m->fLinespace =
fFM.fAscent +
fFM.fDescent;
310 Printf(
"TGFont: %s, %s, ref cnt = %u",
314 Printf(
"TGFont: %s, %s, ref cnt = %u",
fName.Data(),
354 family =
fFA.fFamily;
355 if (strncasecmp(family,
"itc ", 4) == 0) {
358 if ((strcasecmp(family,
"Arial") == 0)
359 || (strcasecmp(family,
"Geneva") == 0)) {
360 family =
"Helvetica";
361 }
else if ((strcasecmp(family,
"Times New Roman") == 0)
362 || (strcasecmp(family,
"New York") == 0)) {
364 }
else if ((strcasecmp(family,
"Courier New") == 0)
365 || (strcasecmp(family,
"Monaco") == 0)) {
367 }
else if (strcasecmp(family,
"AvantGarde") == 0) {
368 family =
"AvantGarde";
369 }
else if (strcasecmp(family,
"ZapfChancery") == 0) {
370 family =
"ZapfChancery";
371 }
else if (strcasecmp(family,
"ZapfDingbats") == 0) {
372 family =
"ZapfDingbats";
382 src = dest = (
char*)dst->
Data() + len;
384 for (; *src !=
'\0'; src++, dest++) {
385 while (isspace(
UChar_t(*src))) {
390 if ((upper != 0) && (islower(
UChar_t(*src)))) {
391 *dest = toupper(
UChar_t(*src));
397 family = (
char *) dst->
Data() + len;
399 if (family != (
char *) dst->
Data() + len) {
401 family = (
char *) dst->
Data() + len;
403 if (strcasecmp(family,
"NewCenturySchoolbook") == 0) {
405 dst->
Append(
"NewCenturySchlbk");
406 family = (
char *) dst->
Data() + len;
413 if (strcmp(family,
"Bookman") == 0) {
414 weightString =
"Light";
415 }
else if (strcmp(family,
"AvantGarde") == 0) {
416 weightString =
"Book";
417 }
else if (strcmp(family,
"ZapfChancery") == 0) {
418 weightString =
"Medium";
421 if ((strcmp(family,
"Bookman") == 0)
422 || (strcmp(family,
"AvantGarde") == 0)) {
423 weightString =
"Demi";
425 weightString =
"Bold";
435 if ((strcmp(family,
"Helvetica") == 0)
436 || (strcmp(family,
"Courier") == 0)
437 || (strcmp(family,
"AvantGarde") == 0)) {
438 slantString =
"Oblique";
440 slantString =
"Italic";
447 if ((slantString.
IsNull()) && (weightString.
IsNull())) {
448 if ((strcmp(family,
"Times") == 0)
449 || (strcmp(family,
"NewCenturySchlbk") == 0)
450 || (strcmp(family,
"Palatino") == 0)) {
459 return fFA.fPointsize;
499 if (maxLength <= 0) {
502 newX = curX = termX = 0;
504 sawNonSpace = !isspace(
UChar_t(*p));
510 if (newX > maxLength) {
536 if ((flags &
kTextPartialOK) && (numChars > 0) && (curX < maxLength)) {
549 if (term == source) {
559 return term - source;
577 numChars = strlen(
string);
592 numChars = strlen(
string);
662 const char *
start, *end, *special;
663 Int_t n,
y=0, charsThisChunk, maxChunks;
664 Int_t baseline,
h, curX, newX, maxWidth;
671 Int_t maxLines, curLine, layoutHeight;
673 lineLengths = staticLineLengths;
676 h =
fFM.fAscent +
fFM.fDescent;
679 numChars = strlen(
string);
684 layout->
fFont =
this;
689 baseline =
fFM.fAscent;
696 end =
string + numChars;
704 if (
start >= special) {
707 for (special =
start; special < end; special++) {
709 if ((*special ==
'\n') || (*special ==
'\r')) {
714 if (*special ==
'\t') {
725 if (
start < special) {
727 wrapLength - curX, flags, &newX);
730 if (charsThisChunk > 0) {
732 charsThisChunk, curX, newX, baseline);
734 start += charsThisChunk;
738 if ((
start == special) && (special < end)) {
743 if (*special ==
'\t') {
746 newchunk =
NewChunk(layout, &maxChunks,
start, 1, curX, newX, baseline);
749 if ((
start < end) && ((wrapLength <= 0) || (newX <= wrapLength))) {
758 newchunk =
NewChunk(layout, &maxChunks,
start, 1, curX, 1000000000, baseline);
776 if (*
start ==
'\t') {
787 if (charsThisChunk > 0) {
799 if (curX > maxWidth) {
806 if (curLine >= maxLines) {
809 newLengths =
new int[2 * maxLines];
810 memcpy((
void *) newLengths, lineLengths, maxLines *
sizeof (
int));
812 if (lineLengths != staticLineLengths) {
813 delete[] lineLengths;
815 lineLengths = newLengths;
818 lineLengths[curLine] = curX;
831 chunk =
NewChunk(layout, &maxChunks,
start, 0, curX, 1000000000, baseline);
845 int extra = maxWidth;
847 if (chunk->
fY !=
y) {
851 if (curLine < maxLines)
852 extra = maxWidth - lineLengths[curLine];
854 chunk->
fX += extra / 2;
862 layout->
fWidth = maxWidth;
863 layoutHeight = baseline -
fFM.fAscent;
885 *height = layoutHeight;
887 if (lineLengths != staticLineLengths) {
888 delete[] lineLengths;
923 Int_t i, numDisplayChars, drawX;
926 if (lastChar < 0) lastChar = 100000000;
931 if ((numDisplayChars > 0) && (firstChar < numDisplayChars)) {
932 if (firstChar <= 0) {
936 fFont->MeasureChars(chunk->
fStart, firstChar, 0, 0, &drawX);
938 if (lastChar < numDisplayChars) numDisplayChars = lastChar;
939 fFont->DrawChars(dst, gc, chunk->
fStart + firstChar, numDisplayChars - firstChar,
940 x + chunk->
fX + drawX,
y + chunk->
fY);
945 if (lastChar <= 0)
break;
970 int xx, yy, width, height;
972 if ((
CharBbox(underline, &xx, &yy, &width, &height) != 0)
975 y + yy +
fFont->fFM.fAscent +
fFont->fUnderlinePos,
1003 Int_t i,
n, dummy, baseline, pos;
1016 baseline = chunk->
fY;
1109 Int_t i, xx = 0, ww = 0;
1124 }
else if (index < chunk->fNumChars) {
1126 fFont->MeasureChars(chunk->
fStart, index, 0, 0, &xx);
1130 fFont->MeasureChars(chunk->
fStart + index, 1, 0, 0, &ww);
1155 *
y = chunk->
fY -
fFont->fFM.fAscent;
1190 Int_t i, x1, x2, y1, y2, xDiff, yDiff, dist, minDist, ascent, descent;
1193 ascent =
fFont->fFM.fAscent;
1194 descent =
fFont->fFM.fDescent;
1199 if (chunk->
fStart[0] ==
'\n') {
1208 y1 = chunk->
fY - ascent;
1210 y2 = chunk->
fY + descent;
1214 }
else if (
x >= x2) {
1222 }
else if (
y >= y2) {
1227 if ((xDiff == 0) && (yDiff == 0)) {
1231 if ((dist < minDist) || !minDist) {
1256 Int_t result, i, x1, y1, x2, y2;
1258 Int_t left, top, right, bottom;
1274 if (chunk->
fStart[0] ==
'\n') {
1283 y1 = chunk->
fY -
fFont->fFM.fAscent;
1285 y2 = chunk->
fY +
fFont->fFM.fDescent;
1287 if ((right < x1) || (left >= x2) || (bottom < y1) || (top >= y2)) {
1292 }
else if ((x1 < left) || (x2 >= right) || (y1 < top) || (y2 >= bottom)) {
1294 }
else if (result == -1) {
1336 Int_t i, j, used,
c, baseline;
1339 baseline = chunk->
fY;
1344 if (baseline != chunk->
fY) {
1348 baseline = chunk->
fY;
1351 if (chunk->
fStart[0] ==
'\t') {
1358 if ((
c ==
'(') || (
c ==
')') || (
c ==
'\\') || (
c < 0x20) || (
c >=
UChar_t(0x7f))) {
1414 maxChunks = *maxPtr;
1416 if (maxChunks == 0) {
1428 *maxPtr = maxChunks;
1461 const char *source,
Int_t numChars,
1469 for (i = 0; i < numChars; i++) {
1491 const char *source,
Int_t numChars,
1496 if ((
x + (max_width * numChars) > 0x7fff)) {
1504 numChars =
MeasureChars(source, numChars, 0x7fff -
x, 0, &length);
1507 gVirtualX->DrawString(dst, gc,
x,
y, source, numChars);
1509 if (
fFA.fUnderline != 0) {
1514 if (
fFA.fOverstrike != 0) {
1515 y -=
fFM.fDescent +
fFM.fAscent / 10;
1557 if (!font || !*font) {
1558 Error(
"GetFont",
"argument may not be 0 or empty");
1607 f->MeasureChars(
"0", 1, 0, 0, &
f->fTabWidth);
1609 if (!
f->fTabWidth) {
1610 f->fTabWidth =
f->fFM.fMaxWidth;
1617 if (!
f->fTabWidth) {
1624 Int_t descent =
f->fFM.fDescent;
1625 f->fUnderlinePos = descent/2;
1626 f->fUnderlineHeight =
f->fFA.fPointsize/10;
1628 if (!
f->fUnderlineHeight) {
1629 f->fUnderlineHeight = 1;
1631 if (
f->fUnderlinePos +
f->fUnderlineHeight > descent) {
1637 f->fUnderlineHeight = descent -
f->fUnderlinePos;
1639 if (!
f->fUnderlineHeight) {
1641 f->fUnderlineHeight = 1;
1719 if (
f->RemoveReference() == 0) {
1746 while ((
f = (
TGFont*) next())) {
1747 if (
f->fFontStruct == font) {
1763 while ((
f = (
TGFont*) next())) {
1764 if (
f->fFontH == font) {
1792 return (
const char *)obj->
GetName();
1805 const char *str = 0;
1841 int len = strlen(str)+1;
1842 result[i] =
new char[len];
1843 strlcpy(result[i], str, len);
1845 result[i] =
new char[20];
1846 snprintf(result[i], 20,
"%d", num);
1887 out <<
" TGFont *ufont; // will reflect user font changes\n";
1907 while (*p && ((*p ==
' ') || (*p ==
'\t'))) {
1922 while (*p && (*p !=
'"')) {
1931 while (*p && (*p !=
' ') && (*p !=
'\t')) {
1962 int len = strlen(
string)+1;
1963 char *str =
new char[len];
1964 strlcpy(str,
string, len);
1966 if (*str ==
'-' || *str ==
'*') {
1995 if ((errno == ERANGE) || (end == s)) {
2055 memset(field,
'\0',
sizeof (field));
2058 if (*str ==
'-') str++;
2061 src = (
char*)ds.
Data();
2064 for (i = 0; *src !=
'\0'; src++) {
2066 *src = tolower(
UChar_t(*src));
2088 field[j + 1] = field[j];
2202 if (!
map->fStrKey) {
2206 for (
m =
map;
m->fStrKey != 0;
m++) {
2207 if (strcasecmp(strKey,
m->fStrKey) == 0) {
2223 for ( ;
map->fStrKey != 0;
map++) {
2224 if (numKey ==
map->fNumKey)
return map->fStrKey;
2244 if (!field || !strlen(field)) {
2249 return (ch !=
'*' && ch !=
'?');
2270 char *family, *end, *p;
2280 nameList =
gVirtualX->ListFonts(
"*", 10000, numNames);
2282 for (i = 0; i < numNames; i++) {
2283 if (nameList[i][0] !=
'-') {
2286 family = strchr(nameList[i] + 1,
'-');
2291 end = strchr(family,
'-');
2296 for (p = family; *p !=
'\0'; p++) {
2307 dst =
new char*[entries+1];
2309 TIter next(&familyTable);
2313 while ((obj = next())) {
2332 for (i = 0;
f[i] != 0; ++i) {
2351 Int_t numNames, score, i, scaleable, pixelsize, xaPixelsize;
2352 Int_t bestIdx, bestScore, bestScaleableIdx, bestScaleableScore;
2358 const char *fmt, *family;
2366 if (pixelsize < 0) {
2368 d = -pixelsize * 25.4/72;
2375 pixelsize = (
int)
d;
2380 fmt =
"-*-%.240s-*-*-*-*-*-*-*-*-*-*-*-*";
2382 nameList =
gVirtualX->ListFonts(buf.
Data(), 32768, numNames);
2389 nameList =
gVirtualX->ListFonts(buf.
Data(), 32768, numNames);
2394 fontStruct =
gVirtualX->LoadQueryFont(
"fixed");
2397 fontStruct =
gVirtualX->LoadQueryFont(
"*");
2411 bestScaleableIdx = 0;
2414 for (i = 0; i < numNames; i++) {
2441 if (xaPixelsize > pixelsize) {
2442 score += (xaPixelsize - pixelsize) * 120;
2444 score += (pixelsize - xaPixelsize) * 100;
2479 if (score < bestScaleableScore) {
2480 bestScaleableIdx = i;
2481 bestScaleableScore = score;
2484 if (score < bestScore) {
2502 if (bestScaleableScore < bestScore) {
2508 str = nameList[bestScaleableIdx];
2510 str = strchr(str + 1,
'-');
2514 rest = strchr(rest + 1,
'-');
2517 buf =
TString::Format(
"%.240s-*-%d-*-*-*-*-*%s", nameList[bestScaleableIdx], pixelsize, rest);
2523 buf = nameList[bestIdx];
2531 if (bestScaleableScore <
kMaxInt) {
2542 font =
MakeFont(fontPtr, fontStruct, buf);
2561 fixedDefault = fixedDefault && ((*
name ==
'-') || (*
name ==
'*'));
2562 fontStruct =
fClient->GetFontByName(
name, fixedDefault);
2584 const char *fontName)
2588 Int_t i, width, firstChar, lastChar,
n, replaceOK;
2597 newFont =
new TGFont(fontName);
2619 gVirtualX->GetFontProperties(fontStruct, ascent, descent);
2634 for (i = 0; i < 256; i++) {
2635 if ((i == 160) || (i == 173) || (i == 177) ||
2636 (i < firstChar) || (i > lastChar)) {
2648 char ch[2] = {0, 0};
2650 for (i = 0; i < 256; i++) {
2661 }
else if (width !=
n) {
2679 for (i = 0; i < 256; i++) {
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index).
Handle_t Drawable_t
Drawable handle.
Handle_t GContext_t
Graphics context handle.
Handle_t FontStruct_t
Pointer to font structure.
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
externInt_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
static const FontStateMap_t gWeightMap[]
static char * GetToken(char *str)
static const FontStateMap_t gXlfdCharsetMap[]
static const FontStateMap_t gUnderlineMap[]
static const FontStateMap_t gOverstrikeMap[]
static int GetControlCharSubst(int c, char buf[4])
When displaying text in a widget, a backslashed escape sequence is substituted for control characters...
static const FontStateMap_t gXlfdSlantMap[]
static const FontStateMap_t gSlantMap[]
static const FontStateMap_t gXlfdgWeightMap[]
static const FontStateMap_t gXlfdSetwidthMap[]
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Bool_t ParseFontName(const char *string, FontAttributes_t *fa)
Converts a string into a set of font attributes that can be used to construct a font.
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
const char * NameOfFont(TGFont *font)
Given a font, return a textual string identifying it.
char ** GetFontFamilies()
Return information about the font families that are available on the current display.
TGFontPool(const TGFontPool &fp)=delete
Bool_t ParseXLFD(const char *string, XLFDAttributes_t *xa)
Break up a fully specified XLFD into a set of font attributes.
int FindStateNum(const FontStateMap_t *map, const char *strKey)
Given a lookup table, map a string to a number in the table.
TGFont * GetNativeFont(const char *name, Bool_t fixedDefault=kTRUE)
The return value is a pointer to an TGFont object that represents the native font.
const char * GetUid(const char *string)
Given a string, this procedure returns a unique identifier for the string.
Bool_t FieldSpecified(const char *field)
Helper function for ParseXLFD().
TGFont * FindFontByHandle(FontH_t font) const
Find font based on its font handle. Returns 0 if font is not found.
void FreeFont(const TGFont *font)
Free font. If ref count is 0 delete font.
char ** GetAttributeInfo(const FontAttributes_t *fa)
Return information about the font attributes as an array of strings.
const char * FindStateString(const FontStateMap_t *map, int numKey)
Given a lookup table, map a number to a string in the table.
void FreeFontFamilies(char **f)
Delete an array of families allocated GetFontFamilies() method.
TGFont * GetFontFromAttributes(FontAttributes_t *fa, TGFont *fontPtr)
Given a desired set of attributes for a font, find a font with the closest matching attributes and cr...
TGFont * MakeFont(TGFont *font, FontStruct_t fontStruct, const char *fontName)
Helper for GetNativeFont() and GetFontFromAttributes().
~TGFontPool() override
Cleanup font pool.
TGFont * FindFont(FontStruct_t font) const
Find font based on its font struct. Returns 0 if font is not found.
void Print(Option_t *option="") const override
List all fonts in the pool.
void FreeAttributeInfo(char **info)
Free attributes info.
Encapsulate fonts used in the GUI system.
char fTypes[256]
Array giving types of all characters in the font, used when displaying control characters.
void GetFontMetrics(FontMetrics_t *m) const
Get font metrics.
void UnderlineChars(Drawable_t dst, GContext_t gc, const char *string, Int_t x, Int_t y, Int_t firstChar, Int_t lastChar) const
This procedure draws an underline for a given range of characters in a given string.
friend class TGTextLayout
void DrawCharsExp(Drawable_t dst, GContext_t gc, const char *source, Int_t numChars, Int_t x, Int_t y) const
Draw a string of characters on the screen.
Int_t fBarHeight
Height of underline or overstrike bar (used for simulating a native underlined or strikeout font).
TObjString * fNamedHash
Pointer to the named object TGFont was based on.
Int_t fWidths[256]
Array giving widths of all possible characters in the font.
Int_t MeasureChars(const char *source, Int_t numChars, Int_t maxLength, Int_t flags, Int_t *length) const
Determine the number of characters from the string that will fit in the given horizontal span.
~TGFont() override
Delete font.
Int_t fTabWidth
Width of tabs in this font (pixels).
Int_t TextWidth(const char *string, Int_t numChars=-1) const
A wrapper function for the more complicated interface of MeasureChars.
FontH_t fFontH
Font handle (derived from fontstruct).
Int_t fUnderlineHeight
Height of underline bar (used for drawing underlines on a non-underlined font).
FontStruct_t operator()() const
Not inline due to a bug in g++ 2.96 20000731 (Red Hat Linux 7.0).
FontAttributes_t fFA
Actual font attributes obtained when the font was created.
LayoutChunk_t * NewChunk(TGTextLayout *layout, int *maxPtr, const char *start, int numChars, int curX, int newX, int y) const
Helper function for ComputeTextLayout().
FontMetrics_t fFM
Cached font metrics.
Int_t XTextWidth(const char *string, Int_t numChars=-1) const
Return text width in pixels.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save the used font as a C++ statement(s) on output stream out.
TGTextLayout * ComputeTextLayout(const char *string, Int_t numChars, Int_t wrapLength, Int_t justify, Int_t flags, UInt_t *width, UInt_t *height) const
Computes the amount of screen space needed to display a multi-line, justified string of text.
Int_t fUnderlinePos
Offset from baseline to origin of underline bar (used for drawing underlines on a non-underlined font...
Int_t PostscriptFontName(TString *dst) const
Return the name of the corresponding Postscript font for this TGFont.
void DrawChars(Drawable_t dst, GContext_t gc, const char *source, Int_t numChars, Int_t x, Int_t y) const
Perform a quick sanity check to ensure we won't overflow the X coordinate space.
FontStruct_t fFontStruct
Low level graphics fontstruct.
void Print(Option_t *option="") const override
Print font info.
TGClient * fClient
Connection to display server.
void DrawText(Drawable_t dst, GContext_t gc, Int_t x, Int_t y, Int_t firstChar, Int_t lastChar) const
Use the information in the TGTextLayout object to display a multi-line, justified string of text.
Int_t PointToChar(Int_t x, Int_t y) const
Use the information in the TGTextLayout token to determine the character closest to the given point.
Int_t IntersectText(Int_t x, Int_t y, Int_t w, Int_t h) const
Determines whether a text layout lies entirely inside, entirely outside, or overlaps a given rectangl...
const TGFont * fFont
The font used when laying out the text.
void ToPostscript(TString *dst) const
Outputs the contents of a text layout in Postscript format.
Int_t fNumChunks
Number of chunks actually used in following array.
Int_t DistanceToText(Int_t x, Int_t y) const
Computes the distance in pixels from the given point to the given text layout.
Int_t CharBbox(Int_t index, Int_t *x, Int_t *y, Int_t *w, Int_t *h) const
Use the information in the TGTextLayout token to return the bounding box for the character specified ...
LayoutChunk_t * fChunks
Array of chunks. The actual size will be maxChunks.
Int_t fWidth
The maximum width of all lines in the text layout.
void UnderlineChar(Drawable_t dst, GContext_t gc, Int_t x, Int_t y, Int_t underline) const
Use the information in the TGTextLayout object to display an underline below an individual character.
const char * fString
The string that was laid out.
~TGTextLayout() override
destructor
THashTable implements a hash table to store TObject's.
void Add(TObject *obj) override
Add object to the hash table.
TObject * FindObject(const char *name) const override
Find object using its name.
const char * GetName() const override
Returns name of object.
Collectable string class.
TObjString(const char *s="")
const char * GetName() const override
Returns name of object.
virtual const char * GetName() const
Returns name of object.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
UInt_t References() const
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
const char * Data() const
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Double_t Hypot(Double_t x, Double_t y)
Returns sqrt(x*x + y*y).
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.