Logo ROOT  
Reference Guide
TGHtmlDraw.cxx
Go to the documentation of this file.
1// $Id: TGHtmlDraw.cxx,v 1.1 2007/05/04 17:07:01 brun Exp $
2// Author: Valeriy Onuchin 03/05/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**************************************************************************
13
14 HTML widget for xclass. Based on tkhtml 1.28
15 Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
16 Copyright (C) 2002-2003 Hector Peraza.
17
18 This library is free software; you can redistribute it and/or
19 modify it under the terms of the GNU Library General Public
20 License as published by the Free Software Foundation; either
21 version 2 of the License, or (at your option) any later version.
22
23 This library is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 Library General Public License for more details.
27
28 You should have received a copy of the GNU Library General Public
29 License along with this library; if not, write to the Free
30 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
32**************************************************************************/
33
34// Routines used to render HTML onto the screen for the TGHtml widget.
35
36#include <cstring>
37#include <cstdlib>
38
39#include "TGHtml.h"
40#include "TImage.h"
41#include "TVirtualX.h"
42#include "strlcpy.h"
43
44////////////////////////////////////////////////////////////////////////////////
45/// ctor.
46
48{
49 fZ = NULL;
50 fTop = fBottom = 0;
51 fLeft = fRight = 0;
52 fN = 0;
53 fPPrev = fPNext = 0;
54 fBPrev = fBNext = 0;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// dtor.
59
61{
62 if (fZ) delete[] fZ;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Destroy the given Block after first unlinking it from the element list.
67/// Note that this unlinks the block from the element list only -- not from
68/// the block list.
69
71{
72 if (pBlock->fPNext) {
73 pBlock->fPNext->fPPrev = pBlock->fPPrev;
74 } else {
75 fPLast = pBlock->fPPrev;
76 }
77 if (pBlock->fPPrev) {
78 pBlock->fPPrev->fPNext = pBlock->fPNext;
79 } else {
80 fPFirst = pBlock->fPNext;
81 }
82 pBlock->fPPrev = pBlock->fPNext = 0;
83 delete pBlock;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Append a block to the block list and insert the block into the
88/// element list immediately prior to the element given.
89///
90/// pToken - The token that comes after pBlock
91/// pBlock - The block to be appended
92
94{
95 pBlock->fPPrev = pToken->fPPrev;
96 pBlock->fPNext = pToken;
97 pBlock->fBPrev = fLastBlock;
98 pBlock->fBNext = 0;
99 if (fLastBlock) {
100 fLastBlock->fBNext = pBlock;
101 } else {
102 fFirstBlock = pBlock;
103 }
104 fLastBlock = pBlock;
105 if (pToken->fPPrev) {
106 pToken->fPPrev->fPNext = (TGHtmlElement *) pBlock;
107 } else {
108 fPFirst = (TGHtmlElement *) pBlock;
109 }
110 pToken->fPPrev = (TGHtmlElement *) pBlock;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Print an ordered list index into the given buffer. Use numbering
115/// like this:
116///
117/// A B C ... Y Z AA BB CC ... ZZ
118///
119/// Revert to decimal for indices greater than 52.
120
121static void GetLetterIndex(char *zBuf, int index, int isUpper)
122{
123 int seed;
124
125 if (index < 1 || index > 52) {
126 // coverity[secure_coding]: zBuf is large enough for an integer
127 sprintf(zBuf, "%d", index);
128 return;
129 }
130
131 if (isUpper) {
132 seed = 'A';
133 } else {
134 seed = 'a';
135 }
136
137 index--;
138
139 if (index < 26) {
140 zBuf[0] = seed + index;
141 zBuf[1] = 0;
142 } else {
143 index -= 26;
144 zBuf[0] = seed + index;
145 zBuf[1] = seed + index;
146 zBuf[2] = 0;
147 }
148
149 strcat(zBuf, "."); // NOLINT
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Print an ordered list index into the given buffer. Use roman
154/// numerals. For indices greater than a few thousand, revert to
155/// decimal.
156
157static void GetRomanIndex(char *zBuf, int index, int isUpper)
158{
159 int i = 0;
160 UInt_t j;
161
162 static struct {
163 int value;
164 const char *name;
165 } values[] = {
166 { 1000, "m" },
167 { 999, "im" },
168 { 990, "xm" },
169 { 900, "cm" },
170 { 500, "d" },
171 { 499, "id" },
172 { 490, "xd" },
173 { 400, "cd" },
174 { 100, "c" },
175 { 99, "ic" },
176 { 90, "xc" },
177 { 50, "l" },
178 { 49, "il" },
179 { 40, "xl" },
180 { 10, "x" },
181 { 9, "ix" },
182 { 5, "v" },
183 { 4, "iv" },
184 { 1, "i" },
185 };
186
187 if (index < 1 || index >= 5000) {
188 // coverity[secure_coding]: zBuf is large enough for an integer
189 sprintf(zBuf, "%d", index);
190 return;
191 }
192 for (j = 0; index > 0 && j < sizeof(values)/sizeof(values[0]); j++) {
193 int k;
194 while (index >= values[j].value) {
195 for (k = 0; values[j].name[k]; k++) {
196 zBuf[i++] = values[j].name[k];
197 }
198 index -= values[j].value;
199 }
200 }
201 zBuf[i] = 0;
202 if (isUpper) {
203 for (i = 0; zBuf[i]; i++) {
204 zBuf[i] += 'A' - 'a';
205 }
206 }
207
208 strcat(zBuf, "."); // NOLINT
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Draw the selection background for the given block
213///
214/// x, y - Virtual coords of top-left of drawable
215
217 int x, int y)
218{
219 int xLeft, xRight; // Left and right bounds of box to draw
220 int yTop, yBottom; // Top and bottom of box
221 TGHtmlElement *p = 0; // First element of the block
222 TGFont *font=0; // Font
223 GContext_t gc; // GC for drawing
224
225 if (pBlock == 0 || (pBlock->fFlags & HTML_Selected) == 0) return;
226
227 xLeft = pBlock->fLeft - x;
228 if (pBlock == fPSelStartBlock && fSelStartIndex > 0) {
229 if (fSelStartIndex >= pBlock->fN) return;
230 p = pBlock->fPNext;
231 font = GetFont(p->fStyle.fFont);
232 if (font == 0) return;
233 if (p->fType == Html_Text) {
235 xLeft = tp->fX - x + font->TextWidth(pBlock->fZ, fSelStartIndex);
236 }
237 }
238 xRight = pBlock->fRight - x;
239 if (pBlock == fPSelEndBlock && fSelEndIndex < pBlock->fN) {
240 if (p == 0) {
241 p = pBlock->fPNext;
242 font = GetFont(p->fStyle.fFont);
243 if (font == 0) return;
244 }
245 if (p->fType == Html_Text) {
247 xRight = tp->fX - x + font->TextWidth(pBlock->fZ, fSelEndIndex);
248 }
249 }
250 yTop = pBlock->fTop - y;
251 yBottom = pBlock->fBottom - y;
253 Int_t xx = xLeft;
254 Int_t yy = yTop;
255 UInt_t width = xRight - xLeft;
256 UInt_t height = yBottom - yTop;
257 gVirtualX->FillRectangle(drawable, gc, xx, yy, width, height);
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Draw a rectangle. The rectangle will have a 3-D appearance if
262/// flat is 0 and a flat appearance if flat is 1.
263///
264/// depth - width of the relief or the flat line
265
267 int x, int y, int w, int h, int depth, int relief)
268{
269 Int_t xx, yy;
271
272 if (depth > 0) {
273 int i;
274 GContext_t gcLight, gcDark;
275
276 if (relief != HTML_RELIEF_FLAT) {
277 int iLight1, iDark1;
278 iLight1 = GetLightShadowColor(src->fStyle.fBgcolor);
279 gcLight = GetGC(iLight1, FONT_Any);
280 iDark1 = GetDarkShadowColor(src->fStyle.fBgcolor);
281 gcDark = GetGC(iDark1, FONT_Any);
282 if (relief == HTML_RELIEF_SUNKEN) {
283 GContext_t gcTemp = gcLight;
284 gcLight = gcDark;
285 gcDark = gcTemp;
286 }
287 } else {
288 gcLight = GetGC(src->fStyle.fColor, FONT_Any);
289 gcDark = gcLight;
290 }
291 xx = x;
292 yy = y;
293 width = depth;
294 height = h;
295 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
296 xx = x + w - depth;
297 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
298 for (i = 0; i < depth && i < h/2; i++) {
299 gVirtualX->DrawLine(drawable, gcLight, x+i, y+i, x+w-i-1, y+i);
300 gVirtualX->DrawLine(drawable, gcDark, x+i, y+h-i-1, x+w-i-1, y+h-i-1);
301 }
302 }
303 if (h > depth*2 && w > depth*2) {
304 GContext_t gcBg;
305 gcBg = GetGC(src->fStyle.fBgcolor, FONT_Any);
306 xx = x + depth;
307 yy = y + depth;
308 width = w - depth*2;
309 height = h - depth*2;
310 gVirtualX->FillRectangle(drawable, gcBg, xx, yy, width, height);
311 }
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Display a single HtmlBlock. This is where all the drawing happens.
316
318 int drawableLeft, int drawableTop,
319 int drawableWidth, int drawableHeight,
320 Pixmap_t pixmap)
321{
322 TGFont *font; // Font to use to render text
323 GContext_t gc; // A graphics context
324 TGHtmlElement *src; // TGHtmlElement holding style information
325 TGHtmlTable *pTable; // The table (when drawing part of a table)
326 Int_t x, y; // Where to draw
328
329 if (pBlock == 0) return;
330
331 src = pBlock->fPNext;
332 while (src && (src->fFlags & HTML_Visible) == 0) src = src->fPNext;
333
334 if (src == 0) return;
335
336 if (pBlock->fN > 0) {
337 // We must be dealing with plain old text
338 if (src->fType == Html_Text) {
340 x = tsrc->fX;
341 y = tsrc->fY;
342 } else {
344 return;
345 }
346 if (pBlock->fFlags & HTML_Selected) {
347 DrawSelectionBackground(pBlock, drawable, drawableLeft, drawableTop);
348 }
349 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
350 font = GetFont(src->fStyle.fFont);
351 if (font == 0) return;
352 font->DrawChars(drawable, gc, pBlock->fZ, pBlock->fN,
353 x - drawableLeft, y - drawableTop);
354 if (src->fStyle.fFlags & STY_Underline) {
355 font->UnderlineChars(drawable, gc, pBlock->fZ,
356 x - drawableLeft, y-drawableTop, 0, pBlock->fN);
357 }
358 if (src->fStyle.fFlags & STY_StrikeThru) {
359 x = pBlock->fLeft - drawableLeft;
360 y = (pBlock->fTop + pBlock->fBottom) / 2 - drawableTop;
361 width = pBlock->fRight - pBlock->fLeft;
362 height = 1 + (pBlock->fBottom - pBlock->fTop > 15);
363 gVirtualX->FillRectangle(drawable, gc, x, y, width, height);
364 }
365 if (pBlock == fPInsBlock && fInsStatus > 0) {
366 if (fInsIndex < pBlock->fN) {
368 x = tsrc->fX - drawableLeft;
369 x += font->TextWidth(pBlock->fZ, fInsIndex);
370 } else {
371 x = pBlock->fRight - drawableLeft;
372 }
373 if (x > 0) --x;
374 gVirtualX->FillRectangle(drawable, gc, x, pBlock->fTop - drawableTop,
375 2, pBlock->fBottom - pBlock->fTop);
376 }
377 } else {
378 // We are dealing with a single TGHtmlElement which contains something
379 // other than plain text.
380 int cnt, w;
381 constexpr std::size_t zBufSize = 30;
382 char zBuf[zBufSize];
383 TGHtmlLi *li;
384 TGHtmlImageMarkup *image;
385 switch (src->fType) {
386 case Html_LI:
387 li = (TGHtmlLi *) src;
388 x = li->fX;
389 y = li->fY;
390 switch (li->fLtype) {
391 case LI_TYPE_Enum_1:
392 // coverity[secure_coding]: zBuf is large enough for an int
393 snprintf(zBuf, zBufSize, "%d.", li->fCnt);
394 break;
395 case LI_TYPE_Enum_A:
396 GetLetterIndex(zBuf, li->fCnt, 1);
397 break;
398 case LI_TYPE_Enum_a:
399 GetLetterIndex(zBuf, li->fCnt, 0);
400 break;
401 case LI_TYPE_Enum_I:
402 GetRomanIndex(zBuf, li->fCnt, 1);
403 break;
404 case LI_TYPE_Enum_i:
405 GetRomanIndex(zBuf, li->fCnt, 0);
406 break;
407 default:
408 zBuf[0] = 0;
409 break;
410 }
411 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
412 switch (li->fLtype) {
414 case LI_TYPE_Bullet1:
415 //gVirtualX->FillArc(drawable, gc,
416 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
417 // 0, 360*64);
418 break;
419
420 case LI_TYPE_Bullet2:
421 //gVirtualX->DrawArc(drawable, gc,
422 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
423 // 0, 360*64);
424 break;
425
426 case LI_TYPE_Bullet3:
427 gVirtualX->DrawRectangle(drawable, gc, x - 7 - drawableLeft,
428 y - 8 - drawableTop, 7, 7);
429 break;
430
431 case LI_TYPE_Enum_1:
432 case LI_TYPE_Enum_A:
433 case LI_TYPE_Enum_a:
434 case LI_TYPE_Enum_I:
435 case LI_TYPE_Enum_i:
436 cnt = strlen(zBuf);
437 font = GetFont(src->fStyle.fFont);
438 if (font == 0) return;
439 w = font->TextWidth(zBuf, cnt);
440 font->DrawChars(drawable, gc, zBuf, cnt,
441 x - w - drawableLeft, y - drawableTop);
442 break;
443 }
444 break;
445
446 case Html_HR: {
447 TGHtmlHr *hr = (TGHtmlHr *) src;
448 int relief = fRuleRelief;
449 switch (relief) {
452 break;
453 default:
454 relief = HTML_RELIEF_FLAT;
455 break;
456 }
457 DrawRect(drawable, src, hr->fX - drawableLeft, hr->fY - drawableTop,
458 hr->fW, hr->fH, 1, relief);
459 break;
460 }
461
462 case Html_TABLE: {
463 TGHtmlTable *table = (TGHtmlTable *) src;
464 int relief = fTableRelief;
465 if ((!fBgImage || src->fStyle.fExpbg) && !table->fHasbg) {
466 switch (relief) {
469 break;
470 default:
471 relief = HTML_RELIEF_FLAT;
472 break;
473 }
474
475 DrawRect(drawable, src, table->fX - drawableLeft,
476 table->fY - drawableTop, table->fW, table->fH,
477 table->fBorderWidth, relief);
478 }
479
480 if (table->fBgImage) {
481 DrawTableBgnd(table->fX, table->fY, table->fW, table->fH, pixmap,
482 table->fBgImage);
483 }
484 break;
485 }
486
487 case Html_TH:
488 case Html_TD: {
489 TGHtmlCell *cell = (TGHtmlCell *) src;
490 int depth, relief;
491 TImage *bgImg;
492 pTable = cell->fPTable;
493 if ((!fBgImage || src->fStyle.fExpbg) && !(pTable && pTable->fHasbg)) {
494 depth = pTable && (pTable->fBorderWidth > 0);
495 switch (fTableRelief) {
496 case HTML_RELIEF_RAISED: relief = HTML_RELIEF_SUNKEN; break;
497 case HTML_RELIEF_SUNKEN: relief = HTML_RELIEF_RAISED; break;
498 default: relief = HTML_RELIEF_FLAT; break;
499 }
500 DrawRect(drawable, src,
501 cell->fX - drawableLeft, cell->fY - drawableTop,
502 cell->fW, cell->fH, depth, relief);
503 }
504 // See if row has an image
505 if (cell->fBgImage) {
506 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap,
507 cell->fBgImage);
508 } else if (cell->fPRow && (bgImg = ((TGHtmlRef *)cell->fPRow)->fBgImage)) {
509 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap, bgImg);
510 }
511 break;
512 }
513
514 case Html_IMG:
515 image = (TGHtmlImageMarkup *) src;
516 if (image->fPImage) {
517 DrawImage(image, drawable, drawableLeft, drawableTop,
518 drawableLeft + drawableWidth,
519 drawableTop + drawableHeight);
520 } else if (image->fZAlt) {
521 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
522 font = GetFont(src->fStyle.fFont);
523 if (font == 0) return;
524 font->DrawChars(drawable, gc,
525 image->fZAlt, strlen(image->fZAlt),
526 image->fX - drawableLeft,
527 image->fY - drawableTop);
528 }
529 break;
530
531 default:
532 break;
533 }
534 }
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// Draw all or part of an image.
539
541 int drawableLeft, int drawableTop,
542 int drawableRight, int drawableBottom)
543{
544 int imageTop; // virtual canvas coordinate for top of image
545 int x, y; // where to place image on the drawable
546 int imageX, imageY; // \__ Subset of image that fits
547 int imageW, imageH; // / on the drawable
548
549 imageTop = image->fY - image->fAscent;
550 y = imageTop - drawableTop;
551 if (imageTop + image->fH > drawableBottom) {
552 imageH = drawableBottom - imageTop;
553 } else {
554 imageH = image->fH;
555 }
556 if (y < 0) {
557 imageY = -y;
558 imageH += y;
559 y = 0;
560 } else {
561 imageY = 0;
562 }
563 x = image->fX - drawableLeft;
564 if (image->fX + image->fW > drawableRight) {
565 imageW = drawableRight - image->fX;
566 } else {
567 imageW = image->fW;
568 }
569 if (x < 0) {
570 imageX = -x;
571 imageW += x;
572 x = 0;
573 } else {
574 imageX = 0;
575 }
576
577 TImage *img = image->fPImage->fImage;
578
579 imageH = imageH < 0 ? -imageH : imageH;
580 imageW = imageW < 0 ? -imageW : imageW;
581
582 img->PaintImage(drawable, x, y, imageX, imageY, imageW, imageH);
583 //gVirtualX->Update(kFALSE);
584
585 image->fRedrawNeeded = 0;
586}
587
588////////////////////////////////////////////////////////////////////////////////
589///
590///TGImage *img = image->image;
591
593{
594 //if (!img->IsAnimated()) return;
595 //img->NextFrame();
596 //delete image->timer;
597 //image->timer = new TTimer(this, img->GetAnimDelay());
598 //ImageChanged(image, image->fW, image->fH);
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Recompute the following fields of the given block structure:
603///
604/// base.count The number of elements described by this
605/// block structure.
606///
607/// n The number of characters of text output
608/// associated with this block. If the block
609/// renders something other than text (ex: `<IMG>`)
610/// then set n to 0.
611///
612/// z Pointer to malloced memory containing the
613/// text associated with this block. `NULL` if
614/// n is 0.
615///
616/// Return a pointer to the first TGHtmlElement not covered by the block.
617
619{
620
621 TGHtmlElement *pElem;
622 int go, i, n, x, y;
624 char zBuf[2000];
625
626 // Reset n and z
627
628 if (p->fN) p->fN = 0;
629
630 if (p->fZ) delete[] p->fZ;
631 p->fZ = 0;
632
633 // Skip over TGHtmlElements that aren't directly displayed.
634
635 pElem = p->fPNext;
636 p->fCount = 0;
637 while (pElem && (pElem->fFlags & HTML_Visible) == 0) {
638 TGHtmlElement *fPNext = pElem->fPNext;
639 if (pElem->fType == Html_Block) {
641 } else {
642 p->fCount++;
643 }
644 pElem = fPNext;
645 }
646 if (pElem == 0) return 0;
647
648 // Handle "special" elements.
649
650 if (pElem->fType != Html_Text) {
651 switch (pElem->fType) {
652 case Html_HR: {
653 TGHtmlHr *hr = (TGHtmlHr *) pElem;
654 p->fTop = hr->fY - hr->fH;
655 p->fBottom = hr->fY;
656 p->fLeft = hr->fX;
657 p->fRight = hr->fX + hr->fW;
658 break;
659 }
660
661 case Html_LI: {
662 TGHtmlLi *li = (TGHtmlLi *) pElem;
663 p->fTop = li->fY - li->fAscent;
664 p->fBottom = li->fY + li->fDescent;
665 p->fLeft = li->fX - 10;
666 p->fRight = li->fX + 10;
667 break;
668 }
669
670 case Html_TD:
671 case Html_TH: {
672 TGHtmlCell *cell = (TGHtmlCell *) pElem;
673 p->fTop = cell->fY;
674 p->fBottom = cell->fY + cell->fH;
675 p->fLeft = cell->fX;
676 p->fRight = cell->fX + cell->fW;
677 break;
678 }
679
680 case Html_TABLE: {
681 TGHtmlTable *table = (TGHtmlTable *) pElem;
682 p->fTop = table->fY;
683 p->fBottom = table->fY + table->fH;
684 p->fLeft = table->fX;
685 p->fRight = table->fX + table->fW;
686 break;
687 }
688
689 case Html_IMG: {
690 TGHtmlImageMarkup *image = (TGHtmlImageMarkup *) pElem;
691 p->fTop = image->fY - image->fAscent;
692 p->fBottom = image->fY + image->fDescent;
693 p->fLeft = image->fX;
694 p->fRight = image->fX + image->fW;
695 break;
696 }
697 }
698 p->fCount++;
699
700 return pElem->fPNext;
701 }
702
703 // If we get this far, we must be dealing with text.
704
706 n = 0;
707 x = text->fX;
708 y = text->fY;
709 p->fTop = y - text->fAscent;
710 p->fBottom = y + text->fDescent;
711 p->fLeft = x;
712 style = pElem->fStyle;
713 go = 1;
714 while (pElem) {
715 TGHtmlElement *fPNext = pElem->fPNext;
716 switch (pElem->fType) {
717 case Html_Text: {
718 TGHtmlTextElement *txt = (TGHtmlTextElement *) pElem;
719 if (pElem->fFlags & STY_Invisible) {
720 break;
721 }
722 if (txt->fSpaceWidth <= 0) {
723 //CANT_HAPPEN;
724 break;
725 }
726 if (y != txt->fY
727 || style.fFont != pElem->fStyle.fFont
728 || style.fColor != pElem->fStyle.fColor
729 || (style.fFlags & STY_FontMask)
730 != (pElem->fStyle.fFlags & STY_FontMask)) {
731 go = 0;
732 } else {
733 int sw = txt->fSpaceWidth;
734 int nSpace = (txt->fX - x) / sw;
735 if (nSpace * sw + x != txt->fX) {
736 go = 0;
737 } else if ((n + nSpace + pElem->fCount) >= (int)sizeof(zBuf)) {
738 // go = 0; - this caused a hang, instead lets do what we can
739 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
740 zBuf[n++] = ' ';
741 }
742 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
743 zBuf[sizeof(zBuf)-1] = 0;
744 n += i;
745 x = txt->fX + txt->fW;
746 } else {
747 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
748 zBuf[n++] = ' ';
749 }
750 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
751 zBuf[sizeof(zBuf)-1] = 0;
752 n += pElem->fCount;
753 x = txt->fX + txt->fW;
754 }
755 }
756 break;
757 }
758
759 case Html_Space:
760 if (pElem->fStyle.fFont != style.fFont) {
761 pElem = pElem->fPNext;
762 go = 0;
763 } else if ((style.fFlags & STY_Preformatted) != 0 &&
764 (pElem->fFlags & HTML_NewLine) != 0) {
765 pElem = pElem->fPNext;
766 go = 0;
767 }
768 break;
769
770 case Html_Block:
772 break;
773
774 case Html_A:
775 case Html_EndA:
776 go = 0;
777 break;
778
779 default:
780 if (pElem->fFlags & HTML_Visible) go = 0;
781 break;
782 }
783 if (go == 0) break;
784 p->fCount++;
785 pElem = fPNext;
786 }
787 p->fRight = x;
788
789 while (n > 0 && zBuf[n-1] == ' ') n--;
790 p->fZ = new char[n+1];
791 strlcpy(p->fZ, zBuf, n+1);
792 p->fZ[n] = 0;
793 p->fN = n;
794
795 return pElem;
796}
797
798////////////////////////////////////////////////////////////////////////////////
799/// Scan ahead looking for a place to put a block. Return a pointer
800/// to the element which should come immediately after the block.
801///
802/// if pCnt != 0, then put the number of elements skipped in *pCnt.
803///
804/// p - First candidate for the start of a block
805/// pCnt - Write number of elements skipped here
806
808{
809 int cnt = 0;
810
811 while (p && (p->fFlags & HTML_Visible) == 0) {
812 TGHtmlElement *fPNext = p->fPNext;
813 if (p->fType == Html_Block) {
815 } else {
816 cnt++;
817 }
818 p = fPNext;
819 }
820 if (pCnt) *pCnt = cnt;
821
822 return p;
823}
824
825////////////////////////////////////////////////////////////////////////////////
826/// Add additional blocks to the block list in order to cover
827/// all elements on the element list.
828///
829/// If any old blocks are found on the element list, they must
830/// be left over from a prior rendering. Unlink and delete them.
831
833{
834 TGHtmlElement *pElem;
835
836 if (fLastBlock) {
837 pElem = FillOutBlock(fLastBlock);
838 } else {
839 pElem = fPFirst;
840 }
841 while (pElem) {
842 int cnt;
843 pElem = FindStartOfNextBlock(pElem, &cnt);
844 if (pElem) {
845 TGHtmlBlock *pNew = new TGHtmlBlock();
846 if (fLastBlock) {
848 }
849 AppendBlock(pElem, pNew);
850 pElem = FillOutBlock(pNew);
851 }
852 }
853}
854
855////////////////////////////////////////////////////////////////////////////////
856/// Draw table background
857
858void TGHtml::DrawTableBgnd(int l, int t, int w, int h,
859 Drawable_t pixmap, TImage *image)
860{
861 //int mx, my, sh, sw, sx, sy, hd;
862 int dl, dt, dr, db, left, top, right, bottom;
863
864 left = l - fVisible.fX;
865 top = t - fVisible.fY;
866
867 dl = fDirtyLeft;
868 dt = fDirtyTop;
869 dr = fDirtyRight;
870 db = fDirtyBottom;
871
872 right = left + w - 1;
873 bottom = top + h - 1;
874 if (dr == 0 && db == 0) { dr = right; db = bottom; }
875 if (left > dr || right < dl || top > db || bottom < dt) return;
876
877#if 0
878 int iw = image->GetWidth();
879 int ih = image->GetHeight();
880 if (iw < 4 && ih < 4) return; // CPU burners we ignore.
881 sx = (left + _visibleStart.x) % iw; // X offset within image to start from
882 sw = iw - sx; // Width of section of image to draw.
883 for (mx = left - dl; w > 0; mx += sw, sw = iw, sx = 0) {
884 if (sw > w) sw = w;
885 sy = (top + _visibleStart.y) % ih; // Y offset within image to start from
886 sh = ih - sy; // Height of section of image to draw.
887 for (my = top - dt, hd = h; hd > 0; my += sh, sh = ih, sy = 0) {
888 if (sh > hd) sh = hd;
889 // printf("image: %d %d %d %d %d %d\n", sx, sy, sw, sh, mx,my);
890 image->Draw(pixmap, GetAnyGC(), sx, sy, sw, sh, mx, my);
891 hd -= sh;
892 }
893 w -= sw;
894 }
895#else
896 if (!image->GetPixmap()) return;
898 GCValues_t gcv;
899 // unsigned int mask = kGCTile | kGCFillStyle |
900 // kGCTileStipXOrigin | kGCTileStipYOrigin;
901 gcv.fTile = image->GetPixmap();
905 gVirtualX->ChangeGC(gc, &gcv);
906
907 gVirtualX->FillRectangle(pixmap, gc, left - dl, top - dt, w, h);
908
909 // mask = kGCFillStyle;
911 gVirtualX->ChangeGC(gc, &gcv);
912#endif
913}
Handle_t Pixmap_t
Pixmap handle.
Definition: GuiTypes.h:30
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
Handle_t Drawable_t
Drawable handle.
Definition: GuiTypes.h:31
@ kFillSolid
Definition: GuiTypes.h:51
@ kFillTiled
Definition: GuiTypes.h:51
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:46
static void GetLetterIndex(char *zBuf, int index, int isUpper)
Print an ordered list index into the given buffer.
Definition: TGHtmlDraw.cxx:121
static void GetRomanIndex(char *zBuf, int index, int isUpper)
Print an ordered list index into the given buffer.
Definition: TGHtmlDraw.cxx:157
@ Html_HR
Definition: TGHtmlTokens.h:111
@ Html_TD
Definition: TGHtmlTokens.h:174
@ Html_LI
Definition: TGHtmlTokens.h:122
@ Html_TABLE
Definition: TGHtmlTokens.h:172
@ Html_TH
Definition: TGHtmlTokens.h:178
@ Html_Block
Definition: TGHtmlTokens.h:45
@ Html_Space
Definition: TGHtmlTokens.h:43
@ Html_Text
Definition: TGHtmlTokens.h:42
@ Html_A
Definition: TGHtmlTokens.h:46
@ Html_IMG
Definition: TGHtmlTokens.h:117
@ Html_EndA
Definition: TGHtmlTokens.h:47
#define STY_FontMask
Definition: TGHtml.h:241
#define LI_TYPE_Enum_a
Definition: TGHtml.h:444
#define HTML_Selected
Definition: TGHtml.h:277
#define COLOR_Selection
Definition: TGHtml.h:200
#define LI_TYPE_Bullet2
Definition: TGHtml.h:440
#define HTML_Visible
Definition: TGHtml.h:275
#define STY_Invisible
Definition: TGHtml.h:240
#define HTML_RELIEF_FLAT
Definition: TGHtml.h:51
#define LI_TYPE_Bullet1
Definition: TGHtml.h:439
#define FONT_Any
Definition: TGHtml.h:173
#define LI_TYPE_Enum_1
Definition: TGHtml.h:442
#define HTML_RELIEF_SUNKEN
Definition: TGHtml.h:52
#define CANT_HAPPEN
Definition: TGHtml.h:60
#define HTML_RELIEF_RAISED
Definition: TGHtml.h:53
#define HTML_NewLine
Definition: TGHtml.h:276
#define LI_TYPE_Undefined
Definition: TGHtml.h:438
#define STY_StrikeThru
Definition: TGHtml.h:235
#define STY_Underline
Definition: TGHtml.h:236
#define STY_Preformatted
Definition: TGHtml.h:234
#define LI_TYPE_Enum_i
Definition: TGHtml.h:446
#define LI_TYPE_Bullet3
Definition: TGHtml.h:441
#define LI_TYPE_Enum_I
Definition: TGHtml.h:445
#define LI_TYPE_Enum_A
Definition: TGHtml.h:443
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t style
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char mx
char name[80]
Definition: TGX11.cxx:110
#define gVirtualX
Definition: TVirtualX.h:338
#define snprintf
Definition: civetweb.c:1540
Encapsulate fonts used in the GUI system.
Definition: TGFont.h:140
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.
Definition: TGFont.cxx:617
Int_t TextWidth(const char *string, Int_t numChars=-1) const
A wrapper function for the more complicated interface of MeasureChars.
Definition: TGFont.cxx:575
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.
Definition: TGFont.cxx:1493
TGHtmlBlock * fBNext
Definition: TGHtml.h:721
Html_u16_t fN
Definition: TGHtml.h:720
Html_u16_t fRight
Definition: TGHtml.h:719
char * fZ
Definition: TGHtml.h:717
Html_u16_t fLeft
Definition: TGHtml.h:719
int fTop
Definition: TGHtml.h:718
TGHtmlBlock * fBPrev
Definition: TGHtml.h:721
virtual ~TGHtmlBlock()
dtor.
Definition: TGHtmlDraw.cxx:60
TGHtmlBlock()
ctor.
Definition: TGHtmlDraw.cxx:47
int fBottom
Definition: TGHtml.h:718
Html_32_t fH
Definition: TGHtml.h:392
TImage * fBgImage
Definition: TGHtml.h:396
Html_16_t fX
Definition: TGHtml.h:389
Html_16_t fW
Definition: TGHtml.h:390
TGHtmlTable * fPTable
Definition: TGHtml.h:393
Html_32_t fY
Definition: TGHtml.h:391
TGHtmlElement * fPRow
Definition: TGHtml.h:394
Html_u8_t fFlags
Definition: TGHtml.h:266
Html_u8_t fType
Definition: TGHtml.h:265
SHtmlStyle_t fStyle
Definition: TGHtml.h:264
TGHtmlElement * fPPrev
Definition: TGHtml.h:263
Html_16_t fCount
Definition: TGHtml.h:267
TGHtmlElement * fPNext
Definition: TGHtml.h:262
Html_32_t fY
Definition: TGHtml.h:654
Html_u16_t fW
Definition: TGHtml.h:656
Html_u16_t fX
Definition: TGHtml.h:655
Html_u16_t fH
Definition: TGHtml.h:656
TGHtmlImage * fPImage
Definition: TGHtml.h:552
Html_16_t fAscent
Definition: TGHtml.h:547
Html_u8_t fRedrawNeeded
Definition: TGHtml.h:543
Html_32_t fY
Definition: TGHtml.h:550
Html_16_t fW
Definition: TGHtml.h:546
Html_16_t fDescent
Definition: TGHtml.h:548
Html_16_t fH
Definition: TGHtml.h:545
Html_16_t fX
Definition: TGHtml.h:549
const char * fZAlt
Definition: TGHtml.h:551
TImage * fImage
Definition: TGHtml.h:519
Html_u8_t fDescent
Definition: TGHtml.h:426
Html_u8_t fAscent
Definition: TGHtml.h:425
Html_32_t fY
Definition: TGHtml.h:429
Html_16_t fX
Definition: TGHtml.h:428
Html_16_t fCnt
Definition: TGHtml.h:427
Html_u8_t fLtype
Definition: TGHtml.h:424
Html_u8_t fBorderWidth
Definition: TGHtml.h:360
int fHasbg
Definition: TGHtml.h:371
Html_32_t fY
Definition: TGHtml.h:363
Html_16_t fX
Definition: TGHtml.h:365
Html_16_t fW
Definition: TGHtml.h:366
Html_32_t fH
Definition: TGHtml.h:364
TImage * fBgImage
Definition: TGHtml.h:370
Html_16_t fW
Definition: TGHtml.h:297
Html_u8_t fSpaceWidth
Definition: TGHtml.h:300
Html_32_t fY
Definition: TGHtml.h:295
Html_16_t fX
Definition: TGHtml.h:296
char * fZText
Definition: TGHtml.h:301
int GetLightShadowColor(int iBgColor)
Given that the background color is iBgColor, figure out an appropriate color for the bright part of t...
Definition: TGHtml.cxx:1734
TGHtmlBlock * fLastBlock
Definition: TGHtml.h:1144
TGHtmlBlock * fPSelStartBlock
Definition: TGHtml.h:1158
TGHtmlElement * fPFirst
Definition: TGHtml.h:1136
virtual TGFont * GetFont(int iFont)
The rendering and layout routines should call this routine in order to get a font structure.
Definition: TGHtml.cxx:1465
void BlockDraw(TGHtmlBlock *pBlock, Drawable_t wid, int left, int top, int width, int height, Pixmap_t pixmap)
Display a single HtmlBlock. This is where all the drawing happens.
Definition: TGHtmlDraw.cxx:317
void AppendBlock(TGHtmlElement *pToken, TGHtmlBlock *pBlock)
Append a block to the block list and insert the block into the element list immediately prior to the ...
Definition: TGHtmlDraw.cxx:93
void DrawImage(TGHtmlImageMarkup *image, Drawable_t wid, int left, int top, int right, int bottom)
Draw all or part of an image.
Definition: TGHtmlDraw.cxx:540
void AnimateImage(TGHtmlImage *image)
TGImage *img = image->image;.
Definition: TGHtmlDraw.cxx:592
TGHtmlBlock * fPInsBlock
Definition: TGHtml.h:1171
TGHtmlBlock * fPSelEndBlock
Definition: TGHtml.h:1162
void FormBlocks()
Add additional blocks to the block list in order to cover all elements on the element list.
Definition: TGHtmlDraw.cxx:832
TGHtmlElement * FillOutBlock(TGHtmlBlock *p)
Recompute the following fields of the given block structure:
Definition: TGHtmlDraw.cxx:618
int fDirtyBottom
Definition: TGHtml.h:1277
int fInsIndex
Definition: TGHtml.h:1172
int fDirtyRight
Definition: TGHtml.h:1277
void DrawRect(Drawable_t drawable, TGHtmlElement *src, int x, int y, int w, int h, int depth, int relief)
Draw a rectangle.
Definition: TGHtmlDraw.cxx:266
GContext_t GetAnyGC()
Retrieve any valid GC.
Definition: TGHtml.cxx:1117
TGHtmlElement * FindStartOfNextBlock(TGHtmlElement *p, int *pCnt)
Scan ahead looking for a place to put a block.
Definition: TGHtmlDraw.cxx:807
Html_16_t fSelStartIndex
Definition: TGHtml.h:1159
TGHtmlBlock * fFirstBlock
Definition: TGHtml.h:1143
void DrawTableBgnd(int x, int y, int w, int h, Drawable_t d, TImage *image)
Draw table background.
Definition: TGHtmlDraw.cxx:858
Html_16_t fSelEndIndex
Definition: TGHtml.h:1161
int fDirtyTop
Definition: TGHtml.h:1274
void DrawSelectionBackground(TGHtmlBlock *pBlock, Drawable_t Drawable_t, int x, int y)
Draw the selection background for the given block.
Definition: TGHtmlDraw.cxx:216
int fDirtyLeft
Definition: TGHtml.h:1274
TGHtmlElement * fPLast
Definition: TGHtml.h:1137
int fRuleRelief
Definition: TGHtml.h:1266
GContext_t GetGC(int color, int font)
Return a GC from the cache.
Definition: TGHtml.cxx:1047
TImage * fBgImage
Definition: TGHtml.h:1246
int fTableRelief
Definition: TGHtml.h:1265
int GetDarkShadowColor(int iBgColor)
Given that the background color is iBgColor, figure out an appropriate color for the dark part of a 3...
Definition: TGHtml.cxx:1692
int fInsStatus
Definition: TGHtml.h:1168
void UnlinkAndFreeBlock(TGHtmlBlock *pBlock)
Destroy the given Block after first unlinking it from the element list.
Definition: TGHtmlDraw.cxx:70
Long_t fX
x position
Definition: TGDimension.h:56
Long_t fY
y position
Definition: TGDimension.h:57
TGLongPosition fVisible
position of visible region
Definition: TGView.h:32
An abstract interface to image processing library.
Definition: TImage.h:29
virtual UInt_t GetWidth() const
Definition: TImage.h:228
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
virtual void PaintImage(Drawable_t, Int_t, Int_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0, Option_t *="")
Definition: TImage.h:243
virtual UInt_t GetHeight() const
Definition: TImage.h:229
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:267
SCoord_t fY
Definition: TPoint.h:36
SCoord_t fX
Definition: TPoint.h:35
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
const char * cnt
Definition: TXMLSetup.cxx:75
Graphics context structure.
Definition: GuiTypes.h:224
Pixmap_t fTile
tile pixmap for tiling operations
Definition: GuiTypes.h:238
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition: GuiTypes.h:234
Int_t fTsXOrigin
offset for tile or stipple operations
Definition: GuiTypes.h:240
Int_t fTsYOrigin
Definition: GuiTypes.h:241
unsigned int fColor
Definition: TGHtml.h:146
unsigned int fFont
Definition: TGHtml.h:145
unsigned int fFlags
Definition: TGHtml.h:151
TLine l
Definition: textangle.C:4