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 <string.h>
37#include <stdlib.h>
38
39#include "TGHtml.h"
40#include "TImage.h"
41#include "TVirtualX.h"
42
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, ".");
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, ".");
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;
270 UInt_t width, height;
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
327 UInt_t width, height;
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) {
339 TGHtmlTextElement *tsrc = (TGHtmlTextElement *) src;
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) {
367 TGHtmlTextElement *tsrc = (TGHtmlTextElement *) src;
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 char zBuf[30];
382 TGHtmlLi *li;
383 TGHtmlImageMarkup *image;
384 switch (src->fType) {
385 case Html_LI:
386 li = (TGHtmlLi *) src;
387 x = li->fX;
388 y = li->fY;
389 switch (li->fLtype) {
390 case LI_TYPE_Enum_1:
391 // coverity[secure_coding]: zBuf is large enough for an int
392 sprintf(zBuf, "%d.", li->fCnt);
393 break;
394 case LI_TYPE_Enum_A:
395 GetLetterIndex(zBuf, li->fCnt, 1);
396 break;
397 case LI_TYPE_Enum_a:
398 GetLetterIndex(zBuf, li->fCnt, 0);
399 break;
400 case LI_TYPE_Enum_I:
401 GetRomanIndex(zBuf, li->fCnt, 1);
402 break;
403 case LI_TYPE_Enum_i:
404 GetRomanIndex(zBuf, li->fCnt, 0);
405 break;
406 default:
407 zBuf[0] = 0;
408 break;
409 }
410 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
411 switch (li->fLtype) {
413 case LI_TYPE_Bullet1:
414 //gVirtualX->FillArc(drawable, gc,
415 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
416 // 0, 360*64);
417 break;
418
419 case LI_TYPE_Bullet2:
420 //gVirtualX->DrawArc(drawable, gc,
421 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
422 // 0, 360*64);
423 break;
424
425 case LI_TYPE_Bullet3:
426 gVirtualX->DrawRectangle(drawable, gc, x - 7 - drawableLeft,
427 y - 8 - drawableTop, 7, 7);
428 break;
429
430 case LI_TYPE_Enum_1:
431 case LI_TYPE_Enum_A:
432 case LI_TYPE_Enum_a:
433 case LI_TYPE_Enum_I:
434 case LI_TYPE_Enum_i:
435 cnt = strlen(zBuf);
436 font = GetFont(src->fStyle.fFont);
437 if (font == 0) return;
438 w = font->TextWidth(zBuf, cnt);
439 font->DrawChars(drawable, gc, zBuf, cnt,
440 x - w - drawableLeft, y - drawableTop);
441 break;
442 }
443 break;
444
445 case Html_HR: {
446 TGHtmlHr *hr = (TGHtmlHr *) src;
447 int relief = fRuleRelief;
448 switch (relief) {
451 break;
452 default:
453 relief = HTML_RELIEF_FLAT;
454 break;
455 }
456 DrawRect(drawable, src, hr->fX - drawableLeft, hr->fY - drawableTop,
457 hr->fW, hr->fH, 1, relief);
458 break;
459 }
460
461 case Html_TABLE: {
462 TGHtmlTable *table = (TGHtmlTable *) src;
463 int relief = fTableRelief;
464 if ((!fBgImage || src->fStyle.fExpbg) && !table->fHasbg) {
465 switch (relief) {
468 break;
469 default:
470 relief = HTML_RELIEF_FLAT;
471 break;
472 }
473
474 DrawRect(drawable, src, table->fX - drawableLeft,
475 table->fY - drawableTop, table->fW, table->fH,
476 table->fBorderWidth, relief);
477 }
478
479 if (table->fBgImage) {
480 DrawTableBgnd(table->fX, table->fY, table->fW, table->fH, pixmap,
481 table->fBgImage);
482 }
483 break;
484 }
485
486 case Html_TH:
487 case Html_TD: {
488 TGHtmlCell *cell = (TGHtmlCell *) src;
489 int depth, relief;
490 TImage *bgImg;
491 pTable = cell->fPTable;
492 if ((!fBgImage || src->fStyle.fExpbg) && !(pTable && pTable->fHasbg)) {
493 depth = pTable && (pTable->fBorderWidth > 0);
494 switch (fTableRelief) {
495 case HTML_RELIEF_RAISED: relief = HTML_RELIEF_SUNKEN; break;
496 case HTML_RELIEF_SUNKEN: relief = HTML_RELIEF_RAISED; break;
497 default: relief = HTML_RELIEF_FLAT; break;
498 }
499 DrawRect(drawable, src,
500 cell->fX - drawableLeft, cell->fY - drawableTop,
501 cell->fW, cell->fH, depth, relief);
502 }
503 // See if row has an image
504 if (cell->fBgImage) {
505 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap,
506 cell->fBgImage);
507 } else if (cell->fPRow && (bgImg = ((TGHtmlRef *)cell->fPRow)->fBgImage)) {
508 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap, bgImg);
509 }
510 break;
511 }
512
513 case Html_IMG:
514 image = (TGHtmlImageMarkup *) src;
515 if (image->fPImage) {
516 DrawImage(image, drawable, drawableLeft, drawableTop,
517 drawableLeft + drawableWidth,
518 drawableTop + drawableHeight);
519 } else if (image->fZAlt) {
520 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
521 font = GetFont(src->fStyle.fFont);
522 if (font == 0) return;
523 font->DrawChars(drawable, gc,
524 image->fZAlt, strlen(image->fZAlt),
525 image->fX - drawableLeft,
526 image->fY - drawableTop);
527 }
528 break;
529
530 default:
531 break;
532 }
533 }
534}
535
536////////////////////////////////////////////////////////////////////////////////
537/// Draw all or part of an image.
538
540 int drawableLeft, int drawableTop,
541 int drawableRight, int drawableBottom)
542{
543 int imageTop; // virtual canvas coordinate for top of image
544 int x, y; // where to place image on the drawable
545 int imageX, imageY; // \__ Subset of image that fits
546 int imageW, imageH; // / on the drawable
547
548 imageTop = image->fY - image->fAscent;
549 y = imageTop - drawableTop;
550 if (imageTop + image->fH > drawableBottom) {
551 imageH = drawableBottom - imageTop;
552 } else {
553 imageH = image->fH;
554 }
555 if (y < 0) {
556 imageY = -y;
557 imageH += y;
558 y = 0;
559 } else {
560 imageY = 0;
561 }
562 x = image->fX - drawableLeft;
563 if (image->fX + image->fW > drawableRight) {
564 imageW = drawableRight - image->fX;
565 } else {
566 imageW = image->fW;
567 }
568 if (x < 0) {
569 imageX = -x;
570 imageW += x;
571 x = 0;
572 } else {
573 imageX = 0;
574 }
575
576 TImage *img = image->fPImage->fImage;
577
578 imageH = imageH < 0 ? -imageH : imageH;
579 imageW = imageW < 0 ? -imageW : imageW;
580
581 img->PaintImage(drawable, x, y, imageX, imageY, imageW, imageH);
582 //gVirtualX->Update(kFALSE);
583
584 image->fRedrawNeeded = 0;
585}
586
587////////////////////////////////////////////////////////////////////////////////
588///
589///TGImage *img = image->image;
590
592{
593 //if (!img->IsAnimated()) return;
594 //img->NextFrame();
595 //delete image->timer;
596 //image->timer = new TTimer(this, img->GetAnimDelay());
597 //ImageChanged(image, image->fW, image->fH);
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Recompute the following fields of the given block structure:
602///
603/// base.count The number of elements described by this
604/// block structure.
605///
606/// n The number of characters of text output
607/// associated with this block. If the block
608/// renders something other than text (ex: <IMG>)
609/// then set n to 0.
610///
611/// z Pointer to malloced memory containing the
612/// text associated with this block. NULL if
613/// n is 0.
614///
615/// Return a pointer to the first TGHtmlElement not covered by the block.
616
618{
619
620 TGHtmlElement *pElem;
621 int go, i, n, x, y;
623 char zBuf[2000];
624
625 // Reset n and z
626
627 if (p->fN) p->fN = 0;
628
629 if (p->fZ) delete[] p->fZ;
630 p->fZ = 0;
631
632 // Skip over TGHtmlElements that aren't directly displayed.
633
634 pElem = p->fPNext;
635 p->fCount = 0;
636 while (pElem && (pElem->fFlags & HTML_Visible) == 0) {
637 TGHtmlElement *fPNext = pElem->fPNext;
638 if (pElem->fType == Html_Block) {
640 } else {
641 p->fCount++;
642 }
643 pElem = fPNext;
644 }
645 if (pElem == 0) return 0;
646
647 // Handle "special" elements.
648
649 if (pElem->fType != Html_Text) {
650 switch (pElem->fType) {
651 case Html_HR: {
652 TGHtmlHr *hr = (TGHtmlHr *) pElem;
653 p->fTop = hr->fY - hr->fH;
654 p->fBottom = hr->fY;
655 p->fLeft = hr->fX;
656 p->fRight = hr->fX + hr->fW;
657 break;
658 }
659
660 case Html_LI: {
661 TGHtmlLi *li = (TGHtmlLi *) pElem;
662 p->fTop = li->fY - li->fAscent;
663 p->fBottom = li->fY + li->fDescent;
664 p->fLeft = li->fX - 10;
665 p->fRight = li->fX + 10;
666 break;
667 }
668
669 case Html_TD:
670 case Html_TH: {
671 TGHtmlCell *cell = (TGHtmlCell *) pElem;
672 p->fTop = cell->fY;
673 p->fBottom = cell->fY + cell->fH;
674 p->fLeft = cell->fX;
675 p->fRight = cell->fX + cell->fW;
676 break;
677 }
678
679 case Html_TABLE: {
680 TGHtmlTable *table = (TGHtmlTable *) pElem;
681 p->fTop = table->fY;
682 p->fBottom = table->fY + table->fH;
683 p->fLeft = table->fX;
684 p->fRight = table->fX + table->fW;
685 break;
686 }
687
688 case Html_IMG: {
689 TGHtmlImageMarkup *image = (TGHtmlImageMarkup *) pElem;
690 p->fTop = image->fY - image->fAscent;
691 p->fBottom = image->fY + image->fDescent;
692 p->fLeft = image->fX;
693 p->fRight = image->fX + image->fW;
694 break;
695 }
696 }
697 p->fCount++;
698
699 return pElem->fPNext;
700 }
701
702 // If we get this far, we must be dealing with text.
703
705 n = 0;
706 x = text->fX;
707 y = text->fY;
708 p->fTop = y - text->fAscent;
709 p->fBottom = y + text->fDescent;
710 p->fLeft = x;
711 style = pElem->fStyle;
712 go = 1;
713 while (pElem) {
714 TGHtmlElement *fPNext = pElem->fPNext;
715 switch (pElem->fType) {
716 case Html_Text: {
717 TGHtmlTextElement *txt = (TGHtmlTextElement *) pElem;
718 if (pElem->fFlags & STY_Invisible) {
719 break;
720 }
721 if (txt->fSpaceWidth <= 0) {
722 //CANT_HAPPEN;
723 break;
724 }
725 if (y != txt->fY
726 || style.fFont != pElem->fStyle.fFont
727 || style.fColor != pElem->fStyle.fColor
728 || (style.fFlags & STY_FontMask)
729 != (pElem->fStyle.fFlags & STY_FontMask)) {
730 go = 0;
731 } else {
732 int sw = txt->fSpaceWidth;
733 int nSpace = (txt->fX - x) / sw;
734 if (nSpace * sw + x != txt->fX) {
735 go = 0;
736 } else if ((n + nSpace + pElem->fCount) >= (int)sizeof(zBuf)) {
737 // go = 0; - this caused a hang, instead lets do what we can
738 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
739 zBuf[n++] = ' ';
740 }
741 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
742 zBuf[sizeof(zBuf)-1] = 0;
743 n += i;
744 x = txt->fX + txt->fW;
745 } else {
746 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
747 zBuf[n++] = ' ';
748 }
749 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
750 zBuf[sizeof(zBuf)-1] = 0;
751 n += pElem->fCount;
752 x = txt->fX + txt->fW;
753 }
754 }
755 break;
756 }
757
758 case Html_Space:
759 if (pElem->fStyle.fFont != style.fFont) {
760 pElem = pElem->fPNext;
761 go = 0;
762 } else if ((style.fFlags & STY_Preformatted) != 0 &&
763 (pElem->fFlags & HTML_NewLine) != 0) {
764 pElem = pElem->fPNext;
765 go = 0;
766 }
767 break;
768
769 case Html_Block:
771 break;
772
773 case Html_A:
774 case Html_EndA:
775 go = 0;
776 break;
777
778 default:
779 if (pElem->fFlags & HTML_Visible) go = 0;
780 break;
781 }
782 if (go == 0) break;
783 p->fCount++;
784 pElem = fPNext;
785 }
786 p->fRight = x;
787
788 while (n > 0 && zBuf[n-1] == ' ') n--;
789 p->fZ = new char[n+1];
790 strlcpy(p->fZ, zBuf, n+1);
791 p->fZ[n] = 0;
792 p->fN = n;
793
794 return pElem;
795}
796
797////////////////////////////////////////////////////////////////////////////////
798/// Scan ahead looking for a place to put a block. Return a pointer
799/// to the element which should come immediately after the block.
800///
801/// if pCnt != 0, then put the number of elements skipped in *pCnt.
802///
803/// p - First candidate for the start of a block
804/// pCnt - Write number of elements skipped here
805
807{
808 int cnt = 0;
809
810 while (p && (p->fFlags & HTML_Visible) == 0) {
811 TGHtmlElement *fPNext = p->fPNext;
812 if (p->fType == Html_Block) {
814 } else {
815 cnt++;
816 }
817 p = fPNext;
818 }
819 if (pCnt) *pCnt = cnt;
820
821 return p;
822}
823
824////////////////////////////////////////////////////////////////////////////////
825/// Add additional blocks to the block list in order to cover
826/// all elements on the element list.
827///
828/// If any old blocks are found on the element list, they must
829/// be left over from a prior rendering. Unlink and delete them.
830
832{
833 TGHtmlElement *pElem;
834
835 if (fLastBlock) {
836 pElem = FillOutBlock(fLastBlock);
837 } else {
838 pElem = fPFirst;
839 }
840 while (pElem) {
841 int cnt;
842 pElem = FindStartOfNextBlock(pElem, &cnt);
843 if (pElem) {
844 TGHtmlBlock *pNew = new TGHtmlBlock();
845 if (fLastBlock) {
847 }
848 AppendBlock(pElem, pNew);
849 pElem = FillOutBlock(pNew);
850 }
851 }
852}
853
854////////////////////////////////////////////////////////////////////////////////
855/// Draw table background
856
857void TGHtml::DrawTableBgnd(int l, int t, int w, int h,
858 Drawable_t pixmap, TImage *image)
859{
860 //int mx, my, sh, sw, sx, sy, hd;
861 int dl, dt, dr, db, left, top, right, bottom;
862
863 left = l - fVisible.fX;
864 top = t - fVisible.fY;
865
866 dl = fDirtyLeft;
867 dt = fDirtyTop;
868 dr = fDirtyRight;
869 db = fDirtyBottom;
870
871 right = left + w - 1;
872 bottom = top + h - 1;
873 if (dr == 0 && db == 0) { dr = right; db = bottom; }
874 if (left > dr || right < dl || top > db || bottom < dt) return;
875
876#if 0
877 int iw = image->GetWidth();
878 int ih = image->GetHeight();
879 if (iw < 4 && ih < 4) return; // CPU burners we ignore.
880 sx = (left + _visibleStart.x) % iw; // X offset within image to start from
881 sw = iw - sx; // Width of section of image to draw.
882 for (mx = left - dl; w > 0; mx += sw, sw = iw, sx = 0) {
883 if (sw > w) sw = w;
884 sy = (top + _visibleStart.y) % ih; // Y offset within image to start from
885 sh = ih - sy; // Height of section of image to draw.
886 for (my = top - dt, hd = h; hd > 0; my += sh, sh = ih, sy = 0) {
887 if (sh > hd) sh = hd;
888 // printf("image: %d %d %d %d %d %d\n", sx, sy, sw, sh, mx,my);
889 image->Draw(pixmap, GetAnyGC(), sx, sy, sw, sh, mx, my);
890 hd -= sh;
891 }
892 w -= sw;
893 }
894#else
895 if (!image->GetPixmap()) return;
896 GContext_t gc = GetAnyGC();
897 GCValues_t gcv;
898 // unsigned int mask = kGCTile | kGCFillStyle |
899 // kGCTileStipXOrigin | kGCTileStipYOrigin;
900 gcv.fTile = image->GetPixmap();
904 gVirtualX->ChangeGC(gc, &gcv);
905
906 gVirtualX->FillRectangle(pixmap, gc, left - dl, top - dt, w, h);
907
908 // mask = kGCFillStyle;
910 gVirtualX->ChangeGC(gc, &gcv);
911#endif
912}
Handle_t Pixmap_t
Definition: GuiTypes.h:29
Handle_t Drawable_t
Definition: GuiTypes.h:30
@ kFillSolid
Definition: GuiTypes.h:50
@ kFillTiled
Definition: GuiTypes.h:50
Handle_t GContext_t
Definition: GuiTypes.h:37
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:44
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
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:240
#define LI_TYPE_Enum_a
Definition: TGHtml.h:443
#define HTML_Selected
Definition: TGHtml.h:276
#define COLOR_Selection
Definition: TGHtml.h:199
#define LI_TYPE_Bullet2
Definition: TGHtml.h:439
#define HTML_Visible
Definition: TGHtml.h:274
#define STY_Invisible
Definition: TGHtml.h:239
#define HTML_RELIEF_FLAT
Definition: TGHtml.h:50
#define LI_TYPE_Bullet1
Definition: TGHtml.h:438
#define FONT_Any
Definition: TGHtml.h:172
#define LI_TYPE_Enum_1
Definition: TGHtml.h:441
#define HTML_RELIEF_SUNKEN
Definition: TGHtml.h:51
#define CANT_HAPPEN
Definition: TGHtml.h:59
#define HTML_RELIEF_RAISED
Definition: TGHtml.h:52
#define HTML_NewLine
Definition: TGHtml.h:275
#define LI_TYPE_Undefined
Definition: TGHtml.h:437
#define STY_StrikeThru
Definition: TGHtml.h:234
#define STY_Underline
Definition: TGHtml.h:235
#define STY_Preformatted
Definition: TGHtml.h:233
#define LI_TYPE_Enum_i
Definition: TGHtml.h:445
#define LI_TYPE_Bullet3
Definition: TGHtml.h:440
#define LI_TYPE_Enum_I
Definition: TGHtml.h:444
#define LI_TYPE_Enum_A
Definition: TGHtml.h:442
char name[80]
Definition: TGX11.cxx:109
#define gVirtualX
Definition: TVirtualX.h:338
Definition: TGFont.h:149
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:605
Int_t TextWidth(const char *string, Int_t numChars=-1) const
A wrapper function for the more complicated interface of MeasureChars.
Definition: TGFont.cxx:563
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:1478
TGHtmlBlock * fBNext
Definition: TGHtml.h:720
Html_u16_t fN
Definition: TGHtml.h:719
Html_u16_t fRight
Definition: TGHtml.h:718
char * fZ
Definition: TGHtml.h:716
Html_u16_t fLeft
Definition: TGHtml.h:718
int fTop
Definition: TGHtml.h:717
TGHtmlBlock * fBPrev
Definition: TGHtml.h:720
virtual ~TGHtmlBlock()
dtor.
Definition: TGHtmlDraw.cxx:60
TGHtmlBlock()
ctor.
Definition: TGHtmlDraw.cxx:47
int fBottom
Definition: TGHtml.h:717
Html_32_t fH
Definition: TGHtml.h:391
TImage * fBgImage
Definition: TGHtml.h:395
Html_16_t fX
Definition: TGHtml.h:388
Html_16_t fW
Definition: TGHtml.h:389
TGHtmlTable * fPTable
Definition: TGHtml.h:392
Html_32_t fY
Definition: TGHtml.h:390
TGHtmlElement * fPRow
Definition: TGHtml.h:393
Html_u8_t fFlags
Definition: TGHtml.h:265
Html_u8_t fType
Definition: TGHtml.h:264
SHtmlStyle_t fStyle
Definition: TGHtml.h:263
TGHtmlElement * fPPrev
Definition: TGHtml.h:262
Html_16_t fCount
Definition: TGHtml.h:266
TGHtmlElement * fPNext
Definition: TGHtml.h:261
Html_32_t fY
Definition: TGHtml.h:653
Html_u16_t fW
Definition: TGHtml.h:655
Html_u16_t fX
Definition: TGHtml.h:654
Html_u16_t fH
Definition: TGHtml.h:655
TGHtmlImage * fPImage
Definition: TGHtml.h:551
Html_16_t fAscent
Definition: TGHtml.h:546
Html_u8_t fRedrawNeeded
Definition: TGHtml.h:542
Html_32_t fY
Definition: TGHtml.h:549
Html_16_t fW
Definition: TGHtml.h:545
Html_16_t fDescent
Definition: TGHtml.h:547
Html_16_t fH
Definition: TGHtml.h:544
Html_16_t fX
Definition: TGHtml.h:548
const char * fZAlt
Definition: TGHtml.h:550
TImage * fImage
Definition: TGHtml.h:518
Html_u8_t fDescent
Definition: TGHtml.h:425
Html_u8_t fAscent
Definition: TGHtml.h:424
Html_32_t fY
Definition: TGHtml.h:428
Html_16_t fX
Definition: TGHtml.h:427
Html_16_t fCnt
Definition: TGHtml.h:426
Html_u8_t fLtype
Definition: TGHtml.h:423
Html_u8_t fBorderWidth
Definition: TGHtml.h:359
int fHasbg
Definition: TGHtml.h:370
Html_32_t fY
Definition: TGHtml.h:362
Html_16_t fX
Definition: TGHtml.h:364
Html_16_t fW
Definition: TGHtml.h:365
Html_32_t fH
Definition: TGHtml.h:363
TImage * fBgImage
Definition: TGHtml.h:369
Html_16_t fW
Definition: TGHtml.h:296
Html_u8_t fSpaceWidth
Definition: TGHtml.h:299
Html_32_t fY
Definition: TGHtml.h:294
Html_16_t fX
Definition: TGHtml.h:295
char * fZText
Definition: TGHtml.h:300
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:1676
TGHtmlBlock * fLastBlock
Definition: TGHtml.h:1136
TGHtmlBlock * fPSelStartBlock
Definition: TGHtml.h:1150
TGHtmlElement * fPFirst
Definition: TGHtml.h:1128
virtual TGFont * GetFont(int iFont)
The rendering and layout routines should call this routine in order to get a font structure.
Definition: TGHtml.cxx:1407
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:539
void AnimateImage(TGHtmlImage *image)
TGImage *img = image->image;.
Definition: TGHtmlDraw.cxx:591
TGHtmlBlock * fPInsBlock
Definition: TGHtml.h:1163
TGHtmlBlock * fPSelEndBlock
Definition: TGHtml.h:1154
void FormBlocks()
Add additional blocks to the block list in order to cover all elements on the element list.
Definition: TGHtmlDraw.cxx:831
TGHtmlElement * FillOutBlock(TGHtmlBlock *p)
Recompute the following fields of the given block structure:
Definition: TGHtmlDraw.cxx:617
int fDirtyBottom
Definition: TGHtml.h:1268
int fInsIndex
Definition: TGHtml.h:1164
int fDirtyRight
Definition: TGHtml.h:1268
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:1106
TGHtmlElement * FindStartOfNextBlock(TGHtmlElement *p, int *pCnt)
Scan ahead looking for a place to put a block.
Definition: TGHtmlDraw.cxx:806
Html_16_t fSelStartIndex
Definition: TGHtml.h:1151
TGHtmlBlock * fFirstBlock
Definition: TGHtml.h:1135
void DrawTableBgnd(int x, int y, int w, int h, Drawable_t d, TImage *image)
Draw table background.
Definition: TGHtmlDraw.cxx:857
Html_16_t fSelEndIndex
Definition: TGHtml.h:1153
int fDirtyTop
Definition: TGHtml.h:1265
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:1265
TGHtmlElement * fPLast
Definition: TGHtml.h:1129
int fRuleRelief
Definition: TGHtml.h:1257
GContext_t GetGC(int color, int font)
Return a GC from the cache.
Definition: TGHtml.cxx:1036
TImage * fBgImage
Definition: TGHtml.h:1237
int fTableRelief
Definition: TGHtml.h:1256
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:1634
int fInsStatus
Definition: TGHtml.h:1160
void UnlinkAndFreeBlock(TGHtmlBlock *pBlock)
Destroy the given Block after first unlinking it from the element list.
Definition: TGHtmlDraw.cxx:70
TGLongPosition fVisible
Definition: TGView.h:52
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:195
Double_t fY
Y position of text (left,center,etc..)
Definition: TText.h:27
Double_t fX
X position of text (left,center,etc..)
Definition: TText.h:26
TText * text
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:74
Pixmap_t fTile
Definition: GuiTypes.h:237
Int_t fFillStyle
Definition: GuiTypes.h:233
Int_t fTsXOrigin
Definition: GuiTypes.h:239
Int_t fTsYOrigin
Definition: GuiTypes.h:240
unsigned int fColor
Definition: TGHtml.h:145
unsigned int fExpbg
Definition: TGHtml.h:149
unsigned int fBgcolor
Definition: TGHtml.h:148
unsigned int fFont
Definition: TGHtml.h:144
unsigned int fFlags
Definition: TGHtml.h:150
TCanvas * style()
Definition: style.C:1
auto * l
Definition: textangle.C:4