Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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)[30], int index, int isUpper)
122{
123 int seed;
124
125 if (index < 1 || index > 52) {
126 snprintf(zBuf, 30, "%d", index);
127 return;
128 }
129
130 if (isUpper) {
131 seed = 'A';
132 } else {
133 seed = 'a';
134 }
135
136 index--;
137
138 if (index < 26) {
139 zBuf[0] = seed + index;
140 zBuf[1] = 0;
141 } else {
142 index -= 26;
143 zBuf[0] = seed + index;
144 zBuf[1] = seed + index;
145 zBuf[2] = 0;
146 }
147
148 strcat(zBuf, "."); // NOLINT
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Print an ordered list index into the given buffer. Use roman
153/// numerals. For indices greater than a few thousand, revert to
154/// decimal.
155
156static void GetRomanIndex(char (&zBuf)[30], int index, int isUpper)
157{
158 int i = 0;
159 UInt_t j;
160
161 static struct {
162 int value;
163 const char *name;
164 } values[] = {
165 { 1000, "m" },
166 { 999, "im" },
167 { 990, "xm" },
168 { 900, "cm" },
169 { 500, "d" },
170 { 499, "id" },
171 { 490, "xd" },
172 { 400, "cd" },
173 { 100, "c" },
174 { 99, "ic" },
175 { 90, "xc" },
176 { 50, "l" },
177 { 49, "il" },
178 { 40, "xl" },
179 { 10, "x" },
180 { 9, "ix" },
181 { 5, "v" },
182 { 4, "iv" },
183 { 1, "i" },
184 };
185
186 if (index < 1 || index >= 5000) {
187 snprintf(zBuf, 30, "%d", index);
188 return;
189 }
190 for (j = 0; index > 0 && j < sizeof(values)/sizeof(values[0]); j++) {
191 int k;
192 while (index >= values[j].value) {
193 for (k = 0; values[j].name[k]; k++) {
194 zBuf[i++] = values[j].name[k];
195 }
196 index -= values[j].value;
197 }
198 }
199 zBuf[i] = 0;
200 if (isUpper) {
201 for (i = 0; zBuf[i]; i++) {
202 zBuf[i] += 'A' - 'a';
203 }
204 }
205
206 strcat(zBuf, "."); // NOLINT
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Draw the selection background for the given block
211///
212/// x, y - Virtual coords of top-left of drawable
213
215 int x, int y)
216{
217 int xLeft, xRight; // Left and right bounds of box to draw
218 int yTop, yBottom; // Top and bottom of box
219 TGHtmlElement *p = 0; // First element of the block
220 TGFont *font=0; // Font
221 GContext_t gc; // GC for drawing
222
223 if (pBlock == 0 || (pBlock->fFlags & HTML_Selected) == 0) return;
224
225 xLeft = pBlock->fLeft - x;
226 if (pBlock == fPSelStartBlock && fSelStartIndex > 0) {
227 if (fSelStartIndex >= pBlock->fN) return;
228 p = pBlock->fPNext;
229 font = GetFont(p->fStyle.fFont);
230 if (font == 0) return;
231 if (p->fType == Html_Text) {
233 xLeft = tp->fX - x + font->TextWidth(pBlock->fZ, fSelStartIndex);
234 }
235 }
236 xRight = pBlock->fRight - x;
237 if (pBlock == fPSelEndBlock && fSelEndIndex < pBlock->fN) {
238 if (p == 0) {
239 p = pBlock->fPNext;
240 font = GetFont(p->fStyle.fFont);
241 if (font == 0) return;
242 }
243 if (p->fType == Html_Text) {
245 xRight = tp->fX - x + font->TextWidth(pBlock->fZ, fSelEndIndex);
246 }
247 }
248 yTop = pBlock->fTop - y;
249 yBottom = pBlock->fBottom - y;
251 Int_t xx = xLeft;
252 Int_t yy = yTop;
253 UInt_t width = xRight - xLeft;
254 UInt_t height = yBottom - yTop;
255 gVirtualX->FillRectangle(drawable, gc, xx, yy, width, height);
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Draw a rectangle. The rectangle will have a 3-D appearance if
260/// flat is 0 and a flat appearance if flat is 1.
261///
262/// depth - width of the relief or the flat line
263
265 int x, int y, int w, int h, int depth, int relief)
266{
267 Int_t xx, yy;
269
270 if (depth > 0) {
271 int i;
272 GContext_t gcLight, gcDark;
273
274 if (relief != HTML_RELIEF_FLAT) {
275 int iLight1, iDark1;
276 iLight1 = GetLightShadowColor(src->fStyle.fBgcolor);
277 gcLight = GetGC(iLight1, FONT_Any);
278 iDark1 = GetDarkShadowColor(src->fStyle.fBgcolor);
279 gcDark = GetGC(iDark1, FONT_Any);
280 if (relief == HTML_RELIEF_SUNKEN) {
281 GContext_t gcTemp = gcLight;
282 gcLight = gcDark;
283 gcDark = gcTemp;
284 }
285 } else {
286 gcLight = GetGC(src->fStyle.fColor, FONT_Any);
287 gcDark = gcLight;
288 }
289 xx = x;
290 yy = y;
291 width = depth;
292 height = h;
293 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
294 xx = x + w - depth;
295 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
296 for (i = 0; i < depth && i < h/2; i++) {
297 gVirtualX->DrawLine(drawable, gcLight, x+i, y+i, x+w-i-1, y+i);
298 gVirtualX->DrawLine(drawable, gcDark, x+i, y+h-i-1, x+w-i-1, y+h-i-1);
299 }
300 }
301 if (h > depth*2 && w > depth*2) {
302 GContext_t gcBg;
303 gcBg = GetGC(src->fStyle.fBgcolor, FONT_Any);
304 xx = x + depth;
305 yy = y + depth;
306 width = w - depth*2;
307 height = h - depth*2;
308 gVirtualX->FillRectangle(drawable, gcBg, xx, yy, width, height);
309 }
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Display a single HtmlBlock. This is where all the drawing happens.
314
316 int drawableLeft, int drawableTop,
317 int drawableWidth, int drawableHeight,
318 Pixmap_t pixmap)
319{
320 TGFont *font; // Font to use to render text
321 GContext_t gc; // A graphics context
322 TGHtmlElement *src; // TGHtmlElement holding style information
323 TGHtmlTable *pTable; // The table (when drawing part of a table)
324 Int_t x, y; // Where to draw
326
327 if (pBlock == 0) return;
328
329 src = pBlock->fPNext;
330 while (src && (src->fFlags & HTML_Visible) == 0) src = src->fPNext;
331
332 if (src == 0) return;
333
334 if (pBlock->fN > 0) {
335 // We must be dealing with plain old text
336 if (src->fType == Html_Text) {
338 x = tsrc->fX;
339 y = tsrc->fY;
340 } else {
342 return;
343 }
344 if (pBlock->fFlags & HTML_Selected) {
345 DrawSelectionBackground(pBlock, drawable, drawableLeft, drawableTop);
346 }
347 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
348 font = GetFont(src->fStyle.fFont);
349 if (font == 0) return;
350 font->DrawChars(drawable, gc, pBlock->fZ, pBlock->fN,
351 x - drawableLeft, y - drawableTop);
352 if (src->fStyle.fFlags & STY_Underline) {
353 font->UnderlineChars(drawable, gc, pBlock->fZ,
354 x - drawableLeft, y-drawableTop, 0, pBlock->fN);
355 }
356 if (src->fStyle.fFlags & STY_StrikeThru) {
357 x = pBlock->fLeft - drawableLeft;
358 y = (pBlock->fTop + pBlock->fBottom) / 2 - drawableTop;
359 width = pBlock->fRight - pBlock->fLeft;
360 height = 1 + (pBlock->fBottom - pBlock->fTop > 15);
361 gVirtualX->FillRectangle(drawable, gc, x, y, width, height);
362 }
363 if (pBlock == fPInsBlock && fInsStatus > 0) {
364 if (fInsIndex < pBlock->fN) {
366 x = tsrc->fX - drawableLeft;
367 x += font->TextWidth(pBlock->fZ, fInsIndex);
368 } else {
369 x = pBlock->fRight - drawableLeft;
370 }
371 if (x > 0) --x;
372 gVirtualX->FillRectangle(drawable, gc, x, pBlock->fTop - drawableTop,
373 2, pBlock->fBottom - pBlock->fTop);
374 }
375 } else {
376 // We are dealing with a single TGHtmlElement which contains something
377 // other than plain text.
378 int cnt, w;
379 constexpr std::size_t zBufSize = 30;
380 char zBuf[zBufSize];
381 TGHtmlLi *li;
382 TGHtmlImageMarkup *image;
383 switch (src->fType) {
384 case Html_LI:
385 li = (TGHtmlLi *) src;
386 x = li->fX;
387 y = li->fY;
388 switch (li->fLtype) {
389 case LI_TYPE_Enum_1:
390 // coverity[secure_coding]: zBuf is large enough for an int
391 snprintf(zBuf, zBufSize, "%d.", li->fCnt);
392 break;
393 case LI_TYPE_Enum_A:
394 GetLetterIndex(zBuf, li->fCnt, 1);
395 break;
396 case LI_TYPE_Enum_a:
397 GetLetterIndex(zBuf, li->fCnt, 0);
398 break;
399 case LI_TYPE_Enum_I:
400 GetRomanIndex(zBuf, li->fCnt, 1);
401 break;
402 case LI_TYPE_Enum_i:
403 GetRomanIndex(zBuf, li->fCnt, 0);
404 break;
405 default:
406 zBuf[0] = 0;
407 break;
408 }
409 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
410 switch (li->fLtype) {
412 case LI_TYPE_Bullet1:
413 //gVirtualX->FillArc(drawable, gc,
414 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
415 // 0, 360*64);
416 break;
417
418 case LI_TYPE_Bullet2:
419 //gVirtualX->DrawArc(drawable, gc,
420 // x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7,
421 // 0, 360*64);
422 break;
423
424 case LI_TYPE_Bullet3:
425 gVirtualX->DrawRectangle(drawable, gc, x - 7 - drawableLeft,
426 y - 8 - drawableTop, 7, 7);
427 break;
428
429 case LI_TYPE_Enum_1:
430 case LI_TYPE_Enum_A:
431 case LI_TYPE_Enum_a:
432 case LI_TYPE_Enum_I:
433 case LI_TYPE_Enum_i:
434 cnt = strlen(zBuf);
435 font = GetFont(src->fStyle.fFont);
436 if (font == 0) return;
437 w = font->TextWidth(zBuf, cnt);
438 font->DrawChars(drawable, gc, zBuf, cnt,
439 x - w - drawableLeft, y - drawableTop);
440 break;
441 }
442 break;
443
444 case Html_HR: {
445 TGHtmlHr *hr = (TGHtmlHr *) src;
446 int relief = fRuleRelief;
447 switch (relief) {
450 break;
451 default:
452 relief = HTML_RELIEF_FLAT;
453 break;
454 }
455 DrawRect(drawable, src, hr->fX - drawableLeft, hr->fY - drawableTop,
456 hr->fW, hr->fH, 1, relief);
457 break;
458 }
459
460 case Html_TABLE: {
461 TGHtmlTable *table = (TGHtmlTable *) src;
462 int relief = fTableRelief;
463 if ((!fBgImage || src->fStyle.fExpbg) && !table->fHasbg) {
464 switch (relief) {
467 break;
468 default:
469 relief = HTML_RELIEF_FLAT;
470 break;
471 }
472
473 DrawRect(drawable, src, table->fX - drawableLeft,
474 table->fY - drawableTop, table->fW, table->fH,
475 table->fBorderWidth, relief);
476 }
477
478 if (table->fBgImage) {
479 DrawTableBgnd(table->fX, table->fY, table->fW, table->fH, pixmap,
480 table->fBgImage);
481 }
482 break;
483 }
484
485 case Html_TH:
486 case Html_TD: {
487 TGHtmlCell *cell = (TGHtmlCell *) src;
488 int depth, relief;
489 TImage *bgImg;
490 pTable = cell->fPTable;
491 if ((!fBgImage || src->fStyle.fExpbg) && !(pTable && pTable->fHasbg)) {
492 depth = pTable && (pTable->fBorderWidth > 0);
493 switch (fTableRelief) {
494 case HTML_RELIEF_RAISED: relief = HTML_RELIEF_SUNKEN; break;
495 case HTML_RELIEF_SUNKEN: relief = HTML_RELIEF_RAISED; break;
496 default: relief = HTML_RELIEF_FLAT; break;
497 }
498 DrawRect(drawable, src,
499 cell->fX - drawableLeft, cell->fY - drawableTop,
500 cell->fW, cell->fH, depth, relief);
501 }
502 // See if row has an image
503 if (cell->fBgImage) {
504 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap,
505 cell->fBgImage);
506 } else if (cell->fPRow && (bgImg = ((TGHtmlRef *)cell->fPRow)->fBgImage)) {
507 DrawTableBgnd(cell->fX, cell->fY, cell->fW, cell->fH, pixmap, bgImg);
508 }
509 break;
510 }
511
512 case Html_IMG:
513 image = (TGHtmlImageMarkup *) src;
514 if (image->fPImage) {
515 DrawImage(image, drawable, drawableLeft, drawableTop,
516 drawableLeft + drawableWidth,
517 drawableTop + drawableHeight);
518 } else if (image->fZAlt) {
519 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
520 font = GetFont(src->fStyle.fFont);
521 if (font == 0) return;
522 font->DrawChars(drawable, gc,
523 image->fZAlt, strlen(image->fZAlt),
524 image->fX - drawableLeft,
525 image->fY - drawableTop);
526 }
527 break;
528
529 default:
530 break;
531 }
532 }
533}
534
535////////////////////////////////////////////////////////////////////////////////
536/// Draw all or part of an image.
537
539 int drawableLeft, int drawableTop,
540 int drawableRight, int drawableBottom)
541{
542 int imageTop; // virtual canvas coordinate for top of image
543 int x, y; // where to place image on the drawable
544 int imageX, imageY; // \__ Subset of image that fits
545 int imageW, imageH; // / on the drawable
546
547 imageTop = image->fY - image->fAscent;
548 y = imageTop - drawableTop;
549 if (imageTop + image->fH > drawableBottom) {
550 imageH = drawableBottom - imageTop;
551 } else {
552 imageH = image->fH;
553 }
554 if (y < 0) {
555 imageY = -y;
556 imageH += y;
557 y = 0;
558 } else {
559 imageY = 0;
560 }
561 x = image->fX - drawableLeft;
562 if (image->fX + image->fW > drawableRight) {
563 imageW = drawableRight - image->fX;
564 } else {
565 imageW = image->fW;
566 }
567 if (x < 0) {
568 imageX = -x;
569 imageW += x;
570 x = 0;
571 } else {
572 imageX = 0;
573 }
574
575 TImage *img = image->fPImage->fImage;
576
577 imageH = imageH < 0 ? -imageH : imageH;
578 imageW = imageW < 0 ? -imageW : imageW;
579
580 img->PaintImage(drawable, x, y, imageX, imageY, imageW, imageH);
581 //gVirtualX->Update(kFALSE);
582
583 image->fRedrawNeeded = 0;
584}
585
586////////////////////////////////////////////////////////////////////////////////
587///
588///TGImage *img = image->image;
589
591{
592 //if (!img->IsAnimated()) return;
593 //img->NextFrame();
594 //delete image->timer;
595 //image->timer = new TTimer(this, img->GetAnimDelay());
596 //ImageChanged(image, image->fW, image->fH);
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Recompute the following fields of the given block structure:
601///
602/// base.count The number of elements described by this
603/// block structure.
604///
605/// n The number of characters of text output
606/// associated with this block. If the block
607/// renders something other than text (ex: `<IMG>`)
608/// then set n to 0.
609///
610/// z Pointer to malloced memory containing the
611/// text associated with this block. `NULL` if
612/// n is 0.
613///
614/// Return a pointer to the first TGHtmlElement not covered by the block.
615
617{
618
619 TGHtmlElement *pElem;
620 int go, i, n, x, y;
622 char zBuf[2000];
623
624 // Reset n and z
625
626 if (p->fN) p->fN = 0;
627
628 if (p->fZ) delete[] p->fZ;
629 p->fZ = 0;
630
631 // Skip over TGHtmlElements that aren't directly displayed.
632
633 pElem = p->fPNext;
634 p->fCount = 0;
635 while (pElem && (pElem->fFlags & HTML_Visible) == 0) {
636 TGHtmlElement *fPNext = pElem->fPNext;
637 if (pElem->fType == Html_Block) {
639 } else {
640 p->fCount++;
641 }
642 pElem = fPNext;
643 }
644 if (pElem == 0) return 0;
645
646 // Handle "special" elements.
647
648 if (pElem->fType != Html_Text) {
649 switch (pElem->fType) {
650 case Html_HR: {
651 TGHtmlHr *hr = (TGHtmlHr *) pElem;
652 p->fTop = hr->fY - hr->fH;
653 p->fBottom = hr->fY;
654 p->fLeft = hr->fX;
655 p->fRight = hr->fX + hr->fW;
656 break;
657 }
658
659 case Html_LI: {
660 TGHtmlLi *li = (TGHtmlLi *) pElem;
661 p->fTop = li->fY - li->fAscent;
662 p->fBottom = li->fY + li->fDescent;
663 p->fLeft = li->fX - 10;
664 p->fRight = li->fX + 10;
665 break;
666 }
667
668 case Html_TD:
669 case Html_TH: {
670 TGHtmlCell *cell = (TGHtmlCell *) pElem;
671 p->fTop = cell->fY;
672 p->fBottom = cell->fY + cell->fH;
673 p->fLeft = cell->fX;
674 p->fRight = cell->fX + cell->fW;
675 break;
676 }
677
678 case Html_TABLE: {
679 TGHtmlTable *table = (TGHtmlTable *) pElem;
680 p->fTop = table->fY;
681 p->fBottom = table->fY + table->fH;
682 p->fLeft = table->fX;
683 p->fRight = table->fX + table->fW;
684 break;
685 }
686
687 case Html_IMG: {
688 TGHtmlImageMarkup *image = (TGHtmlImageMarkup *) pElem;
689 p->fTop = image->fY - image->fAscent;
690 p->fBottom = image->fY + image->fDescent;
691 p->fLeft = image->fX;
692 p->fRight = image->fX + image->fW;
693 break;
694 }
695 }
696 p->fCount++;
697
698 return pElem->fPNext;
699 }
700
701 // If we get this far, we must be dealing with text.
702
704 n = 0;
705 x = text->fX;
706 y = text->fY;
707 p->fTop = y - text->fAscent;
708 p->fBottom = y + text->fDescent;
709 p->fLeft = x;
710 style = pElem->fStyle;
711 go = 1;
712 while (pElem) {
713 TGHtmlElement *fPNext = pElem->fPNext;
714 switch (pElem->fType) {
715 case Html_Text: {
716 TGHtmlTextElement *txt = (TGHtmlTextElement *) pElem;
717 if (pElem->fFlags & STY_Invisible) {
718 break;
719 }
720 if (txt->fSpaceWidth <= 0) {
721 //CANT_HAPPEN;
722 break;
723 }
724 if (y != txt->fY
725 || style.fFont != pElem->fStyle.fFont
726 || style.fColor != pElem->fStyle.fColor
727 || (style.fFlags & STY_FontMask)
728 != (pElem->fStyle.fFlags & STY_FontMask)) {
729 go = 0;
730 } else {
731 int sw = txt->fSpaceWidth;
732 int nSpace = (txt->fX - x) / sw;
733 if (nSpace * sw + x != txt->fX) {
734 go = 0;
735 } else if ((n + nSpace + pElem->fCount) >= (int)sizeof(zBuf)) {
736 // go = 0; - this caused a hang, instead lets do what we can
737 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
738 zBuf[n++] = ' ';
739 }
740 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
741 zBuf[sizeof(zBuf)-1] = 0;
742 n += i;
743 x = txt->fX + txt->fW;
744 } else {
745 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
746 zBuf[n++] = ' ';
747 }
748 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
749 zBuf[sizeof(zBuf)-1] = 0;
750 n += pElem->fCount;
751 x = txt->fX + txt->fW;
752 }
753 }
754 break;
755 }
756
757 case Html_Space:
758 if (pElem->fStyle.fFont != style.fFont) {
759 pElem = pElem->fPNext;
760 go = 0;
761 } else if ((style.fFlags & STY_Preformatted) != 0 &&
762 (pElem->fFlags & HTML_NewLine) != 0) {
763 pElem = pElem->fPNext;
764 go = 0;
765 }
766 break;
767
768 case Html_Block:
770 break;
771
772 case Html_A:
773 case Html_EndA:
774 go = 0;
775 break;
776
777 default:
778 if (pElem->fFlags & HTML_Visible) go = 0;
779 break;
780 }
781 if (go == 0) break;
782 p->fCount++;
783 pElem = fPNext;
784 }
785 p->fRight = x;
786
787 while (n > 0 && zBuf[n-1] == ' ') n--;
788 p->fZ = new char[n+1];
789 strlcpy(p->fZ, zBuf, n+1);
790 p->fZ[n] = 0;
791 p->fN = n;
792
793 return pElem;
794}
795
796////////////////////////////////////////////////////////////////////////////////
797/// Scan ahead looking for a place to put a block. Return a pointer
798/// to the element which should come immediately after the block.
799///
800/// if pCnt != 0, then put the number of elements skipped in *pCnt.
801///
802/// p - First candidate for the start of a block
803/// pCnt - Write number of elements skipped here
804
806{
807 int cnt = 0;
808
809 while (p && (p->fFlags & HTML_Visible) == 0) {
810 TGHtmlElement *fPNext = p->fPNext;
811 if (p->fType == Html_Block) {
813 } else {
814 cnt++;
815 }
816 p = fPNext;
817 }
818 if (pCnt) *pCnt = cnt;
819
820 return p;
821}
822
823////////////////////////////////////////////////////////////////////////////////
824/// Add additional blocks to the block list in order to cover
825/// all elements on the element list.
826///
827/// If any old blocks are found on the element list, they must
828/// be left over from a prior rendering. Unlink and delete them.
829
831{
832 TGHtmlElement *pElem;
833
834 if (fLastBlock) {
835 pElem = FillOutBlock(fLastBlock);
836 } else {
837 pElem = fPFirst;
838 }
839 while (pElem) {
840 int cnt;
841 pElem = FindStartOfNextBlock(pElem, &cnt);
842 if (pElem) {
843 TGHtmlBlock *pNew = new TGHtmlBlock();
844 if (fLastBlock) {
845 fLastBlock->fCount += cnt;
846 }
847 AppendBlock(pElem, pNew);
848 pElem = FillOutBlock(pNew);
849 }
850 }
851}
852
853////////////////////////////////////////////////////////////////////////////////
854/// Draw table background
855
856void TGHtml::DrawTableBgnd(int l, int t, int w, int h,
857 Drawable_t pixmap, TImage *image)
858{
859 //int mx, my, sh, sw, sx, sy, hd;
860 int dl, dt, dr, db, left, top, right, bottom;
861
862 left = l - fVisible.fX;
863 top = t - fVisible.fY;
864
865 dl = fDirtyLeft;
866 dt = fDirtyTop;
867 dr = fDirtyRight;
868 db = fDirtyBottom;
869
870 right = left + w - 1;
871 bottom = top + h - 1;
872 if (dr == 0 && db == 0) { dr = right; db = bottom; }
873 if (left > dr || right < dl || top > db || bottom < dt) return;
874
875#if 0
876 int iw = image->GetWidth();
877 int ih = image->GetHeight();
878 if (iw < 4 && ih < 4) return; // CPU burners we ignore.
879 sx = (left + _visibleStart.x) % iw; // X offset within image to start from
880 sw = iw - sx; // Width of section of image to draw.
881 for (mx = left - dl; w > 0; mx += sw, sw = iw, sx = 0) {
882 if (sw > w) sw = w;
883 sy = (top + _visibleStart.y) % ih; // Y offset within image to start from
884 sh = ih - sy; // Height of section of image to draw.
885 for (my = top - dt, hd = h; hd > 0; my += sh, sh = ih, sy = 0) {
886 if (sh > hd) sh = hd;
887 // printf("image: %d %d %d %d %d %d\n", sx, sy, sw, sh, mx,my);
888 image->Draw(pixmap, GetAnyGC(), sx, sy, sw, sh, mx, my);
889 hd -= sh;
890 }
891 w -= sw;
892 }
893#else
894 if (!image->GetPixmap()) return;
896 GCValues_t gcv;
897 // unsigned int mask = kGCTile | kGCFillStyle |
898 // kGCTileStipXOrigin | kGCTileStipYOrigin;
899 gcv.fTile = image->GetPixmap();
903 gVirtualX->ChangeGC(gc, &gcv);
904
905 gVirtualX->FillRectangle(pixmap, gc, left - dl, top - dt, w, h);
906
907 // mask = kGCFillStyle;
909 gVirtualX->ChangeGC(gc, &gcv);
910#endif
911}
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)[30], int index, int isUpper)
Print an ordered list index into the given buffer.
static void GetRomanIndex(char(&zBuf)[30], int index, int isUpper)
Print an ordered list index into the given buffer.
@ Html_HR
@ Html_TD
@ Html_LI
@ Html_TABLE
@ Html_TH
@ Html_Block
@ Html_Space
@ Html_Text
@ Html_A
@ Html_IMG
@ Html_EndA
#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
~TGHtmlBlock() override
dtor.
Html_u16_t fLeft
Definition TGHtml.h:719
TGHtmlBlock * fBPrev
Definition TGHtml.h:721
TGHtmlBlock()
ctor.
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
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.
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 ...
void DrawImage(TGHtmlImageMarkup *image, Drawable_t wid, int left, int top, int right, int bottom)
Draw all or part of an image.
void AnimateImage(TGHtmlImage *image)
TGImage *img = image->image;.
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.
TGHtmlElement * FillOutBlock(TGHtmlBlock *p)
Recompute the following fields of the given block structure:
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.
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.
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.
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.
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.
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:274
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
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