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 "TASUtils.h"
42#include "TVirtualX.h"
43#include "strlcpy.h"
44
45////////////////////////////////////////////////////////////////////////////////
46/// ctor.
47
49{
50 fZ = NULL;
51 fTop = fBottom = 0;
52 fLeft = fRight = 0;
53 fN = 0;
54 fPPrev = fPNext = 0;
55 fBPrev = fBNext = 0;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// dtor.
60
62{
63 if (fZ) delete[] fZ;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Destroy the given Block after first unlinking it from the element list.
68/// Note that this unlinks the block from the element list only -- not from
69/// the block list.
70
72{
73 if (pBlock->fPNext) {
74 pBlock->fPNext->fPPrev = pBlock->fPPrev;
75 } else {
76 fPLast = pBlock->fPPrev;
77 }
78 if (pBlock->fPPrev) {
79 pBlock->fPPrev->fPNext = pBlock->fPNext;
80 } else {
81 fPFirst = pBlock->fPNext;
82 }
83 pBlock->fPPrev = pBlock->fPNext = 0;
84 delete pBlock;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Append a block to the block list and insert the block into the
89/// element list immediately prior to the element given.
90///
91/// pToken - The token that comes after pBlock
92/// pBlock - The block to be appended
93
95{
96 pBlock->fPPrev = pToken->fPPrev;
97 pBlock->fPNext = pToken;
98 pBlock->fBPrev = fLastBlock;
99 pBlock->fBNext = 0;
100 if (fLastBlock) {
101 fLastBlock->fBNext = pBlock;
102 } else {
103 fFirstBlock = pBlock;
104 }
105 fLastBlock = pBlock;
106 if (pToken->fPPrev) {
107 pToken->fPPrev->fPNext = (TGHtmlElement *) pBlock;
108 } else {
109 fPFirst = (TGHtmlElement *) pBlock;
110 }
111 pToken->fPPrev = (TGHtmlElement *) pBlock;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Print an ordered list index into the given buffer. Use numbering
116/// like this:
117///
118/// A B C ... Y Z AA BB CC ... ZZ
119///
120/// Revert to decimal for indices greater than 52.
121
122static void GetLetterIndex(char (&zBuf)[30], int index, int isUpper)
123{
124 int seed;
125
126 if (index < 1 || index > 52) {
127 snprintf(zBuf, 30, "%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)[30], 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 snprintf(zBuf, 30, "%d", index);
189 return;
190 }
191 for (j = 0; index > 0 && j < sizeof(values)/sizeof(values[0]); j++) {
192 int k;
193 while (index >= values[j].value) {
194 for (k = 0; values[j].name[k]; k++) {
195 zBuf[i++] = values[j].name[k];
196 }
197 index -= values[j].value;
198 }
199 }
200 zBuf[i] = 0;
201 if (isUpper) {
202 for (i = 0; zBuf[i]; i++) {
203 zBuf[i] += 'A' - 'a';
204 }
205 }
206
207 strcat(zBuf, "."); // NOLINT
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Draw the selection background for the given block
212///
213/// x, y - Virtual coords of top-left of drawable
214
216 int x, int y)
217{
218 int xLeft, xRight; // Left and right bounds of box to draw
219 int yTop, yBottom; // Top and bottom of box
220 TGHtmlElement *p = 0; // First element of the block
221 TGFont *font=0; // Font
222 GContext_t gc; // GC for drawing
223
224 if (pBlock == 0 || (pBlock->fFlags & HTML_Selected) == 0) return;
225
226 xLeft = pBlock->fLeft - x;
227 if (pBlock == fPSelStartBlock && fSelStartIndex > 0) {
228 if (fSelStartIndex >= pBlock->fN) return;
229 p = pBlock->fPNext;
230 font = GetFont(p->fStyle.fFont);
231 if (font == 0) return;
232 if (p->fType == Html_Text) {
234 xLeft = tp->fX - x + font->TextWidth(pBlock->fZ, fSelStartIndex);
235 }
236 }
237 xRight = pBlock->fRight - x;
238 if (pBlock == fPSelEndBlock && fSelEndIndex < pBlock->fN) {
239 if (p == 0) {
240 p = pBlock->fPNext;
241 font = GetFont(p->fStyle.fFont);
242 if (font == 0) return;
243 }
244 if (p->fType == Html_Text) {
246 xRight = tp->fX - x + font->TextWidth(pBlock->fZ, fSelEndIndex);
247 }
248 }
249 yTop = pBlock->fTop - y;
250 yBottom = pBlock->fBottom - y;
252 Int_t xx = xLeft;
253 Int_t yy = yTop;
254 UInt_t width = xRight - xLeft;
255 UInt_t height = yBottom - yTop;
256 gVirtualX->FillRectangle(drawable, gc, xx, yy, width, height);
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Draw a rectangle. The rectangle will have a 3-D appearance if
261/// flat is 0 and a flat appearance if flat is 1.
262///
263/// depth - width of the relief or the flat line
264
266 int x, int y, int w, int h, int depth, int relief)
267{
268 Int_t xx, yy;
270
271 if (depth > 0) {
272 int i;
273 GContext_t gcLight, gcDark;
274
275 if (relief != HTML_RELIEF_FLAT) {
276 int iLight1, iDark1;
277 iLight1 = GetLightShadowColor(src->fStyle.fBgcolor);
278 gcLight = GetGC(iLight1, FONT_Any);
279 iDark1 = GetDarkShadowColor(src->fStyle.fBgcolor);
280 gcDark = GetGC(iDark1, FONT_Any);
281 if (relief == HTML_RELIEF_SUNKEN) {
282 GContext_t gcTemp = gcLight;
283 gcLight = gcDark;
284 gcDark = gcTemp;
285 }
286 } else {
287 gcLight = GetGC(src->fStyle.fColor, FONT_Any);
288 gcDark = gcLight;
289 }
290 xx = x;
291 yy = y;
292 width = depth;
293 height = h;
294 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
295 xx = x + w - depth;
296 gVirtualX->FillRectangle(drawable, gcLight, xx, yy, width, height);
297 for (i = 0; i < depth && i < h/2; i++) {
298 gVirtualX->DrawLine(drawable, gcLight, x+i, y+i, x+w-i-1, y+i);
299 gVirtualX->DrawLine(drawable, gcDark, x+i, y+h-i-1, x+w-i-1, y+h-i-1);
300 }
301 }
302 if (h > depth*2 && w > depth*2) {
303 GContext_t gcBg;
304 gcBg = GetGC(src->fStyle.fBgcolor, FONT_Any);
305 xx = x + depth;
306 yy = y + depth;
307 width = w - depth*2;
308 height = h - depth*2;
309 gVirtualX->FillRectangle(drawable, gcBg, xx, yy, width, height);
310 }
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// Display a single HtmlBlock. This is where all the drawing happens.
315
317 int drawableLeft, int drawableTop,
318 int drawableWidth, int drawableHeight,
319 Pixmap_t pixmap)
320{
321 TGFont *font; // Font to use to render text
322 GContext_t gc; // A graphics context
323 TGHtmlElement *src; // TGHtmlElement holding style information
324 TGHtmlTable *pTable; // The table (when drawing part of a table)
325 Int_t x, y; // Where to draw
327
328 if (pBlock == 0) return;
329
330 src = pBlock->fPNext;
331 while (src && (src->fFlags & HTML_Visible) == 0) src = src->fPNext;
332
333 if (src == 0) return;
334
335 if (pBlock->fN > 0) {
336 // We must be dealing with plain old text
337 if (src->fType == Html_Text) {
339 x = tsrc->fX;
340 y = tsrc->fY;
341 } else {
343 return;
344 }
345 if (pBlock->fFlags & HTML_Selected) {
346 DrawSelectionBackground(pBlock, drawable, drawableLeft, drawableTop);
347 }
348 gc = GetGC(src->fStyle.fColor, src->fStyle.fFont);
349 font = GetFont(src->fStyle.fFont);
350 if (font == 0) return;
351 font->DrawChars(drawable, gc, pBlock->fZ, pBlock->fN,
352 x - drawableLeft, y - drawableTop);
353 if (src->fStyle.fFlags & STY_Underline) {
354 font->UnderlineChars(drawable, gc, pBlock->fZ,
355 x - drawableLeft, y-drawableTop, 0, pBlock->fN);
356 }
357 if (src->fStyle.fFlags & STY_StrikeThru) {
358 x = pBlock->fLeft - drawableLeft;
359 y = (pBlock->fTop + pBlock->fBottom) / 2 - drawableTop;
360 width = pBlock->fRight - pBlock->fLeft;
361 height = 1 + (pBlock->fBottom - pBlock->fTop > 15);
362 gVirtualX->FillRectangle(drawable, gc, x, y, width, height);
363 }
364 if (pBlock == fPInsBlock && fInsStatus > 0) {
365 if (fInsIndex < pBlock->fN) {
367 x = tsrc->fX - drawableLeft;
368 x += font->TextWidth(pBlock->fZ, fInsIndex);
369 } else {
370 x = pBlock->fRight - drawableLeft;
371 }
372 if (x > 0) --x;
373 gVirtualX->FillRectangle(drawable, gc, x, pBlock->fTop - drawableTop,
374 2, pBlock->fBottom - pBlock->fTop);
375 }
376 } else {
377 // We are dealing with a single TGHtmlElement which contains something
378 // other than plain text.
379 int cnt, w;
380 constexpr std::size_t zBufSize = 30;
381 char zBuf[zBufSize];
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 snprintf(zBuf, zBufSize, "%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 // no need to paint if any visisble dimension is not-positive
577 // this happens when image is not shown on currently painted region
578 if ((imageH <= 0) || (imageW <= 0))
579 return;
580
581 TImage *img = image->fPImage->fImage;
582 if (!img)
583 return;
584
585 if ((imageX == 0) && (imageY == 0) && (imageW == image->fW) && (imageH == image->fH)) {
586 TASUtils::PaintImage(img, drawable, x, y);
587 } else {
588 std::unique_ptr<TImage> cloned((TImage *) img->Clone("crop_img"));
589 cloned->Crop(imageX, imageY, imageW, imageH);
590 TASUtils::PaintImage(cloned.get(), drawable, x, y);
591 }
592
593 //gVirtualX->Update(kFALSE);
594
595 image->fRedrawNeeded = 0;
596}
597
598////////////////////////////////////////////////////////////////////////////////
599///
600///TGImage *img = image->image;
601
603{
604 //if (!img->IsAnimated()) return;
605 //img->NextFrame();
606 //delete image->timer;
607 //image->timer = new TTimer(this, img->GetAnimDelay());
608 //ImageChanged(image, image->fW, image->fH);
609}
610
611////////////////////////////////////////////////////////////////////////////////
612/// Recompute the following fields of the given block structure:
613///
614/// base.count The number of elements described by this
615/// block structure.
616///
617/// n The number of characters of text output
618/// associated with this block. If the block
619/// renders something other than text (ex: `<IMG>`)
620/// then set n to 0.
621///
622/// z Pointer to malloced memory containing the
623/// text associated with this block. `NULL` if
624/// n is 0.
625///
626/// Return a pointer to the first TGHtmlElement not covered by the block.
627
629{
630
631 TGHtmlElement *pElem;
632 int go, i, n, x, y;
634 char zBuf[2000];
635
636 // Reset n and z
637
638 if (p->fN) p->fN = 0;
639
640 if (p->fZ) delete[] p->fZ;
641 p->fZ = 0;
642
643 // Skip over TGHtmlElements that aren't directly displayed.
644
645 pElem = p->fPNext;
646 p->fCount = 0;
647 while (pElem && (pElem->fFlags & HTML_Visible) == 0) {
648 TGHtmlElement *fPNext = pElem->fPNext;
649 if (pElem->fType == Html_Block) {
651 } else {
652 p->fCount++;
653 }
654 pElem = fPNext;
655 }
656 if (pElem == 0) return 0;
657
658 // Handle "special" elements.
659
660 if (pElem->fType != Html_Text) {
661 switch (pElem->fType) {
662 case Html_HR: {
663 TGHtmlHr *hr = (TGHtmlHr *) pElem;
664 p->fTop = hr->fY - hr->fH;
665 p->fBottom = hr->fY;
666 p->fLeft = hr->fX;
667 p->fRight = hr->fX + hr->fW;
668 break;
669 }
670
671 case Html_LI: {
672 TGHtmlLi *li = (TGHtmlLi *) pElem;
673 p->fTop = li->fY - li->fAscent;
674 p->fBottom = li->fY + li->fDescent;
675 p->fLeft = li->fX - 10;
676 p->fRight = li->fX + 10;
677 break;
678 }
679
680 case Html_TD:
681 case Html_TH: {
682 TGHtmlCell *cell = (TGHtmlCell *) pElem;
683 p->fTop = cell->fY;
684 p->fBottom = cell->fY + cell->fH;
685 p->fLeft = cell->fX;
686 p->fRight = cell->fX + cell->fW;
687 break;
688 }
689
690 case Html_TABLE: {
691 TGHtmlTable *table = (TGHtmlTable *) pElem;
692 p->fTop = table->fY;
693 p->fBottom = table->fY + table->fH;
694 p->fLeft = table->fX;
695 p->fRight = table->fX + table->fW;
696 break;
697 }
698
699 case Html_IMG: {
700 TGHtmlImageMarkup *image = (TGHtmlImageMarkup *) pElem;
701 p->fTop = image->fY - image->fAscent;
702 p->fBottom = image->fY + image->fDescent;
703 p->fLeft = image->fX;
704 p->fRight = image->fX + image->fW;
705 break;
706 }
707 }
708 p->fCount++;
709
710 return pElem->fPNext;
711 }
712
713 // If we get this far, we must be dealing with text.
714
716 n = 0;
717 x = text->fX;
718 y = text->fY;
719 p->fTop = y - text->fAscent;
720 p->fBottom = y + text->fDescent;
721 p->fLeft = x;
722 style = pElem->fStyle;
723 go = 1;
724 while (pElem) {
725 TGHtmlElement *fPNext = pElem->fPNext;
726 switch (pElem->fType) {
727 case Html_Text: {
728 TGHtmlTextElement *txt = (TGHtmlTextElement *) pElem;
729 if (pElem->fFlags & STY_Invisible) {
730 break;
731 }
732 if (txt->fSpaceWidth <= 0) {
733 //CANT_HAPPEN;
734 break;
735 }
736 if (y != txt->fY
737 || style.fFont != pElem->fStyle.fFont
738 || style.fColor != pElem->fStyle.fColor
739 || (style.fFlags & STY_FontMask)
740 != (pElem->fStyle.fFlags & STY_FontMask)) {
741 go = 0;
742 } else {
743 int sw = txt->fSpaceWidth;
744 int nSpace = (txt->fX - x) / sw;
745 if (nSpace * sw + x != txt->fX) {
746 go = 0;
747 } else if ((n + nSpace + pElem->fCount) >= (int)sizeof(zBuf)) {
748 // go = 0; - this caused a hang, instead lets do what we can
749 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
750 zBuf[n++] = ' ';
751 }
752 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
753 zBuf[sizeof(zBuf)-1] = 0;
754 n += i;
755 x = txt->fX + txt->fW;
756 } else {
757 for (i = 0; i < nSpace && (n+1) < (int)sizeof(zBuf); ++i) {
758 zBuf[n++] = ' ';
759 }
760 strncpy(&zBuf[n], txt->fZText, sizeof(zBuf) - n - 1);
761 zBuf[sizeof(zBuf)-1] = 0;
762 n += pElem->fCount;
763 x = txt->fX + txt->fW;
764 }
765 }
766 break;
767 }
768
769 case Html_Space:
770 if (pElem->fStyle.fFont != style.fFont) {
771 pElem = pElem->fPNext;
772 go = 0;
773 } else if ((style.fFlags & STY_Preformatted) != 0 &&
774 (pElem->fFlags & HTML_NewLine) != 0) {
775 pElem = pElem->fPNext;
776 go = 0;
777 }
778 break;
779
780 case Html_Block:
782 break;
783
784 case Html_A:
785 case Html_EndA:
786 go = 0;
787 break;
788
789 default:
790 if (pElem->fFlags & HTML_Visible) go = 0;
791 break;
792 }
793 if (go == 0) break;
794 p->fCount++;
795 pElem = fPNext;
796 }
797 p->fRight = x;
798
799 while (n > 0 && zBuf[n-1] == ' ') n--;
800 p->fZ = new char[n+1];
801 strlcpy(p->fZ, zBuf, n+1);
802 p->fZ[n] = 0;
803 p->fN = n;
804
805 return pElem;
806}
807
808////////////////////////////////////////////////////////////////////////////////
809/// Scan ahead looking for a place to put a block. Return a pointer
810/// to the element which should come immediately after the block.
811///
812/// if pCnt != 0, then put the number of elements skipped in *pCnt.
813///
814/// p - First candidate for the start of a block
815/// pCnt - Write number of elements skipped here
816
818{
819 int cnt = 0;
820
821 while (p && (p->fFlags & HTML_Visible) == 0) {
822 TGHtmlElement *fPNext = p->fPNext;
823 if (p->fType == Html_Block) {
825 } else {
826 cnt++;
827 }
828 p = fPNext;
829 }
830 if (pCnt) *pCnt = cnt;
831
832 return p;
833}
834
835////////////////////////////////////////////////////////////////////////////////
836/// Add additional blocks to the block list in order to cover
837/// all elements on the element list.
838///
839/// If any old blocks are found on the element list, they must
840/// be left over from a prior rendering. Unlink and delete them.
841
843{
844 TGHtmlElement *pElem;
845
846 if (fLastBlock) {
847 pElem = FillOutBlock(fLastBlock);
848 } else {
849 pElem = fPFirst;
850 }
851 while (pElem) {
852 int cnt;
853 pElem = FindStartOfNextBlock(pElem, &cnt);
854 if (pElem) {
855 TGHtmlBlock *pNew = new TGHtmlBlock();
856 if (fLastBlock) {
857 fLastBlock->fCount += cnt;
858 }
859 AppendBlock(pElem, pNew);
860 pElem = FillOutBlock(pNew);
861 }
862 }
863}
864
865////////////////////////////////////////////////////////////////////////////////
866/// Draw table background
867
868void TGHtml::DrawTableBgnd(int l, int t, int w, int h,
869 Drawable_t pixmap, TImage *image)
870{
871 //int mx, my, sh, sw, sx, sy, hd;
872 int dl, dt, dr, db, left, top, right, bottom;
873
874 left = l - fVisible.fX;
875 top = t - fVisible.fY;
876
877 dl = fDirtyLeft;
878 dt = fDirtyTop;
879 dr = fDirtyRight;
880 db = fDirtyBottom;
881
882 right = left + w - 1;
883 bottom = top + h - 1;
884 if (dr == 0 && db == 0) { dr = right; db = bottom; }
885 if (left > dr || right < dl || top > db || bottom < dt) return;
886
887#if 0
888 int iw = image->GetWidth();
889 int ih = image->GetHeight();
890 if (iw < 4 && ih < 4) return; // CPU burners we ignore.
891 sx = (left + _visibleStart.x) % iw; // X offset within image to start from
892 sw = iw - sx; // Width of section of image to draw.
893 for (mx = left - dl; w > 0; mx += sw, sw = iw, sx = 0) {
894 if (sw > w) sw = w;
895 sy = (top + _visibleStart.y) % ih; // Y offset within image to start from
896 sh = ih - sy; // Height of section of image to draw.
897 for (my = top - dt, hd = h; hd > 0; my += sh, sh = ih, sy = 0) {
898 if (sh > hd) sh = hd;
899 // printf("image: %d %d %d %d %d %d\n", sx, sy, sw, sh, mx,my);
900 image->Draw(pixmap, GetAnyGC(), sx, sy, sw, sh, mx, my);
901 hd -= sh;
902 }
903 w -= sw;
904 }
905#else
906 auto img_pixmap = TASUtils::GetPixmap(image);
907 if (!img_pixmap) return;
909 GCValues_t gcv;
910 // unsigned int mask = kGCTile | kGCFillStyle |
911 // kGCTileStipXOrigin | kGCTileStipYOrigin;
912 gcv.fTile = img_pixmap;
916 gVirtualX->ChangeGC(gc, &gcv);
917
918 gVirtualX->FillRectangle(pixmap, gc, left - dl, top - dt, w, h);
919
920 // mask = kGCFillStyle;
922 gVirtualX->ChangeGC(gc, &gcv);
923#endif
924}
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:39
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
@ kFillSolid
Definition GuiTypes.h:52
@ kFillTiled
Definition GuiTypes.h:52
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
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:142
#define gVirtualX
Definition TVirtualX.h:379
static Pixmap_t GetPixmap(TImage *timg)
Returns image pixmap.
Definition TASUtils.cxx:135
static Bool_t PaintImage(TImage *timg, Drawable_t wid, Int_t x, Int_t y, Bool_t opaque=kFALSE)
Paint image on specified window.
Definition TASUtils.cxx:317
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:614
Int_t TextWidth(const char *string, Int_t numChars=-1) const
A wrapper function for the more complicated interface of MeasureChars.
Definition TGFont.cxx:572
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:1490
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:1733
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:1464
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:1116
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:1046
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:1691
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:30
virtual UInt_t GetWidth() const
Definition TImage.h:243
TObject * Clone(const char *="") const override
Make a clone of an object using the Streamer facility.
Definition TImage.h:115
virtual UInt_t GetHeight() const
Definition TImage.h:244
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
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:225
Pixmap_t fTile
tile pixmap for tiling operations
Definition GuiTypes.h:239
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition GuiTypes.h:235
Int_t fTsXOrigin
offset for tile or stipple operations
Definition GuiTypes.h:241
Int_t fTsYOrigin
Definition GuiTypes.h:242
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