Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGHtmlSizer.cxx
Go to the documentation of this file.
1// $Id: TGHtmlSizer.cxx,v 1.2 2007/05/04 20:33:16 rdm Exp $
2// Author: Valeriy Onuchin 03/05/2007
3
4/**************************************************************************
5
6 HTML widget for xclass. Based on tkhtml 1.28
7 Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
8 Copyright (C) 2002-2003 Hector Peraza.
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public
21 License along with this library; if not, write to the Free
22 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24**************************************************************************/
25
26// Routines used to compute the style and size of individual elements.
27
28#include <cstring>
29#include <cstdlib>
30#include <cctype>
31
32#include "TGHtml.h"
33#include "TImage.h"
34#include "TVirtualX.h"
35#include "snprintf.h"
36
37////////////////////////////////////////////////////////////////////////////////
38/// Get the current rendering style. In other words, get the style
39/// that is currently on the top of the style stack.
40
42{
44
45 if (fStyleStack) {
47 } else {
49 style.fColor = COLOR_Normal;
50 style.fBgcolor = COLOR_Background;
51 style.fSubscript = 0;
52 style.fAlign = ALIGN_Left;
53 style.fFlags = 0;
54 style.fExpbg = 0;
55 }
56
57 return style;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Push a new rendering style onto the stack.
62///
63/// tag - Tag for this style. Normally the end-tag such as </h3> or </em>.
64/// style - The style to push
65
67{
69
70 p = new SHtmlStyleStack_t;
71 p->fPNext = fStyleStack;
72 p->fType = tag;
73 p->fStyle = style;
74 fStyleStack = p;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Pop a rendering style off of the stack.
79///
80/// The top-most style on the stack should have a tag equal to "tag".
81/// If not, then we have an HTML coding error. Perhaps something
82/// like this: "Some text <em>Enphasized</i> more text". It is an
83/// interesting problem to figure out how to respond sanely to this
84/// kind of error. Our solution is to keep popping the stack until
85/// we find the correct tag, or until the stack is empty.
86
88{
89 int i, type;
92
93 if (priority[Html_TABLE] == 0) {
94 for (i = 0; i <= Html_TypeCount; i++) priority[i] = 1;
95 priority[Html_TD] = 2;
97 priority[Html_TH] = 2;
99 priority[Html_TR] = 3;
100 priority[Html_EndTR] = 3;
101 priority[Html_TABLE] = 4;
103 }
106 return GetCurrentStyle();
107 }
108 while ((p = fStyleStack) != 0) {
109 type = p->fType;
112 return GetCurrentStyle();
113 }
114 if (type != tag && priority[type] > priority[tag]) {
115 return GetCurrentStyle();
116 }
117 fStyleStack = p->fPNext;
118 delete p;
119 if (type == tag) break;
120 }
121
122 return GetCurrentStyle();
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Change the font size on the given style by the delta-amount given
127
128static void ScaleFont(SHtmlStyle_t *pStyle, int delta)
129{
130 int size = FontSize(pStyle->fFont) + delta;
131
132 if (size < 0) {
133 delta -= size;
134 } else if (size > 6) {
135 delta -= size-6;
136 }
137
138 pStyle->fFont += delta;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Add the STY_Invisible style to every token between p_first and p_last.
143
145{
146 if (p_first == 0) return;
147 p_first = p_first->fPNext;
148 while (p_first && p_first != p_last) {
149 p_first->fStyle.fFlags |= STY_Invisible;
150 p_first = p_first->fPNext;
151 }
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// For the markup <a href=XXX>, find out if the URL has been visited
156/// before or not. Return COLOR_Visited or COLOR_Unvisited, as
157/// appropriate.
158
160{
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Returns coordinates of string str.
166
167static int *GetCoords(const char *str, int *nptr)
168{
169 const char *cp = str;
170 char *ncp;
171 int *cr, i, n = 0, sz = 4;
172
173 cr = new int[sz];
174 while (cp) {
175 while (*cp && (!isdigit(*cp))) cp++;
176 if ((!*cp) || (!isdigit(*cp))) break;
177 cr[n] = (int) strtol(cp, &ncp, 10);
178 if (cp == ncp) break;
179 cp = ncp;
180 n++;
181 if (n >= sz) {
182 int *tmp = new int[sz+4];
183 for (i = 0; i < sz; ++i) tmp[i] = cr[i];
184 delete[] cr;
185 cr = tmp;
186 sz += 4;
187 }
188 }
189 *nptr = n;
190
191 return cr;
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// This routine adds information to the input texts that doesn't change
196/// when the display is resized or when new fonts are selected, etc.
197/// Mostly this means adding style attributes. But other constant
198/// information (such as numbering on `<li>` and images used for `<IMG>`)
199/// is also obtained. The key is that this routine is only called
200/// once, where the sizer and layout routines can be called many times.
201///
202/// This routine is called whenever the list of elements grows. The
203/// style stack is stored as part of the HTML widget so that we can
204/// always continue where we left off the last time.
205///
206/// In addition to adding style, this routine will invoke methods
207/// needed to acquire information about a markup. The IsVisitied()
208/// method is called for each `<a>` and the GetImage() is called
209/// for each `<IMG>` or for each `<LI>` that has a `SRC=` field.
210///
211/// When a markup is inserted or deleted from the token list, the
212/// style routine must be completely rerun from the beginning. So
213/// what we said above, that this routine is only run once, is not
214/// strictly true.
215
217{
218 SHtmlStyle_t style; // Current style
219 int size; // A new font size
220 int i; // Loop counter
221 int paraAlign; // Current paragraph alignment
222 int rowAlign; // Current table row alignment
223 SHtmlStyle_t nextStyle; // Style for next token if useNextStyle==1
224 int useNextStyle = 0; // True if nextStyle is valid
225 const char *z; // A tag parameter's value
226
227 // The size of header fonts relative to the current font size
228 static int header_sizes[] = { +2, +1, 1, 1, -1, -1 };
229
230 // Don't allow recursion
231 if (fFlags & STYLER_RUNNING) return;
233
234 // Load the style state out of the TGHtml object and into local
235 // variables. This is purely a matter of convenience...
236
238 nextStyle = style; //ia: nextStyle was not initialized
241
242 // Loop over tokens
243 while (fPFirst && p) {
244 switch (p->fType) {
245 case Html_A:
246 if (fAnchorStart) {
248 fAnchorStart = 0;
249 fAnchorFlags = 0;
250 }
251 z = p->MarkupArg("href", 0);
252 if (z) {
253 style.fColor = GetLinkColor(z);
254 if (fUnderlineLinks) style.fFlags |= STY_Underline;
258 }
259 break;
260
261 case Html_EndA:
262 if (fAnchorStart) {
263 ((TGHtmlRef *)p)->fPOther = fAnchorStart;
265 fAnchorStart = 0;
266 fAnchorFlags = 0;
267 }
268 break;
269
270 case Html_MAP:
271 break;
272
273 case Html_EndMAP:
274 break;
275
276 case Html_AREA: {
278 z = p->MarkupArg("shape", 0);
279 area->fMType = HTML_MAP_RECT;
280 if (z) {
281 if (strcasecmp(z, "circle") == 0) {
282 area->fMType = HTML_MAP_CIRCLE;
283 } else if (strcasecmp(z,"poly") == 0) {
284 area->fMType = HTML_MAP_POLY;
285 }
286 }
287 z = p->MarkupArg("coords", 0);
288 if (z) {
289 area->fCoords = GetCoords(z, &area->fNum);
290 }
291 break;
292 }
293
294 case Html_ADDRESS:
295 case Html_EndADDRESS:
296 case Html_BLOCKQUOTE:
299 break;
300
301 case Html_APPLET:
302 if (0 /* has ProcessApplet() */) {
304 nextStyle.fFlags |= STY_Invisible;
306 useNextStyle = 1;
307 } else {
309 }
310 break;
311
312 case Html_B:
313 style.fFont = BoldFont(style.fFont);
315 break;
316
317 case Html_BODY:
318 z = p->MarkupArg("text", 0);
319 if (z) {
320 //FreeColor(fApColor[COLOR_Normal]);
322 }
323 z = p->MarkupArg("bgcolor", 0);
324 if (z) {
325 //FreeColor(fApColor[COLOR_Background]);
329 }
330 z = p->MarkupArg("link", 0);
331 if (z) {
332 //FreeColor(fApColor[COLOR_Unvisited]);
334 }
335 z = p->MarkupArg("vlink", 0);
336 if (z) {
337 //FreeColor(fApColor[COLOR_Visited]);
339 }
340 z = p->MarkupArg("alink", 0);
341 if (z) {
342 }
343 z = p->MarkupArg("background", 0);
344 if (z) {
345 z = ResolveUri(z);
346 if (z) {
347 TImage *img = LoadImage(z, 0, 0);
348 if (img) {
349#if 0
350 SetupBackgroundPic(img->GetPicture());
351#else
353 // unsigned int mask;
354
355 // mask = kGCTile | kGCFillStyle | kGCGraphicsExposures;
356 gcv.fTile = img->GetPixmap();
357 gcv.fFillStyle = kFillTiled;
358 gcv.fGraphicsExposures = kTRUE;
359 fCanvas->SetBackgroundPixmap(img->GetPixmap());
360
361 gVirtualX->ChangeGC(fWhiteGC.GetGC(), &gcv);
362
363 //NeedRedraw(TGRectangle(fVisible, fCanvas->GetSize()));
364#endif
365 fBgImage = img;//delete img;
366 }
367 delete [] z;
368 }
369 }
370 break;
371
372 case Html_EndBODY:
373 break;
374
375 case Html_EndAPPLET:
376 case Html_EndB:
377 case Html_EndBIG:
378 case Html_EndCENTER:
379 case Html_EndCITE:
380 case Html_EndCODE:
381 case Html_EndCOMMENT:
382 case Html_EndDFN:
383 case Html_EndEM:
384 case Html_EndFONT:
385 case Html_EndI:
386 case Html_EndKBD:
387 case Html_EndMARQUEE:
388 case Html_EndNOBR:
389 case Html_EndNOFRAMES:
390 case Html_EndNOSCRIPT:
391 case Html_EndNOEMBED:
392 case Html_EndS:
393 case Html_EndSAMP:
394 case Html_EndSMALL:
395 case Html_EndSTRIKE:
396 case Html_EndSTRONG:
397 case Html_EndSUB:
398 case Html_EndSUP:
399 case Html_EndTITLE:
400 case Html_EndTT:
401 case Html_EndU:
402 case Html_EndVAR:
403 style = PopStyleStack(p->fType);
404 break;
405
406 case Html_BASE:
407 z = p->MarkupArg("href", 0);
408 if (z) {
409 char *z1 = ResolveUri(z);
410 if (z1 != 0) {
411 if (fZBaseHref) delete[] fZBaseHref;
412 fZBaseHref = z1;
413 }
414 }
415 break;
416
417 case Html_EndDIV:
419 style = PopStyleStack(p->fType);
420 break;
421
422 case Html_EndBASEFONT:
424 style.fFont = FontFamily(style.fFont) + 2;
425 break;
426
427 case Html_BIG:
428 ScaleFont(&style, 1);
430 break;
431
432 case Html_CAPTION:
433 paraAlign = p->GetAlignment(paraAlign);
434 break;
435
436 case Html_EndCAPTION:
438 break;
439
440 case Html_CENTER:
442 style.fAlign = ALIGN_Center;
444 break;
445
446 case Html_CITE:
447 style.fFont = ItalicFont(style.fFont);
449 break;
450
451 case Html_CODE:
452 style.fFont = CWFont(style.fFont);
454 break;
455
456 case Html_COMMENT:
457 style.fFlags |= STY_Invisible;
459 break;
460
461 case Html_DD:
462 if (fInnerList && fInnerList->fType == Html_DL) {
463 ((TGHtmlRef *)p)->fPOther = fInnerList;
464 } else {
465 ((TGHtmlRef *)p)->fPOther = 0;
466 }
467 fInDt = 0;
468 break;
469
470 case Html_DFN:
471 style.fFont = ItalicFont(style.fFont);
473 break;
474
475 case Html_DIR:
476 case Html_MENU:
477 case Html_UL: {
479 list->fLPrev = fInnerList;
480 list->fCnt = 0;
481 fInnerList = list;
482 if (list->fLPrev == 0) {
483 list->fLtype = LI_TYPE_Bullet1;
484 list->fCompact = (list->MarkupArg("compact", 0) != 0);
485 } else if (list->fLPrev->fLPrev == 0) {
486 list->fLtype = LI_TYPE_Bullet2;
487 list->fCompact = 1;
488 } else {
489 list->fLtype = LI_TYPE_Bullet3;
490 list->fCompact = 1;
491 }
492 list->fLtype = list->GetUnorderedListType(list->fLtype);
493 break;
494 }
495
496 case Html_EndDL:
497 fInDt = 0;
498 /* Fall thru into the next case */
499 case Html_EndDIR:
500 case Html_EndMENU:
501 case Html_EndOL:
502 case Html_EndUL:
503 ((TGHtmlRef *)p)->fPOther = fInnerList;
505 break;
506
507 case Html_DIV:
509 style.fAlign = p->GetAlignment(style.fAlign);
511 break;
512
513 case Html_DT:
514 if (fInnerList && fInnerList->fType == Html_DL) {
515 ((TGHtmlRef *)p)->fPOther = fInnerList;
516 } else {
517 ((TGHtmlRef *)p)->fPOther = 0;
518 }
519 fInDt = STY_DT;
520 break;
521
522 case Html_EndDD:
523 case Html_EndDT:
524 fInDt = 0;
525 break;
526
527 case Html_DL: {
529 list->fLPrev = fInnerList;
530 list->fCnt = 0;
531 fInnerList = list;
532 list->fCompact = (list->MarkupArg("compact", 0) != 0);
533 fInDt = 0;
534 break;
535 }
536
537 case Html_EM:
538 style.fFont = ItalicFont(style.fFont);
540 break;
541
542 case Html_EMBED:
543 break;
544
545 case Html_BASEFONT:
546 case Html_FONT:
547 z = p->MarkupArg("size", 0);
548 if (z && !fOverrideFonts) {
549 if (*z == '-') {
550 size = FontSize(style.fFont) - atoi(&z[1]) +1;
551 } else if (*z == '+') {
552 size = FontSize(style.fFont) + atoi(&z[1]) +1;
553 } else {
554 size = atoi(z);
555 }
556 if (size <= 0) size = 1;
557 if (size >= N_FONT_SIZE) size = N_FONT_SIZE - 1;
558 style.fFont = FontFamily(style.fFont) + size - 1;
559 }
560 z = p->MarkupArg("color", 0);
561 if (z && *z && !fOverrideColors) style.fColor = GetColorByName(z);
562 PushStyleStack(p->fType == Html_FONT ?
564 break;
565
566 case Html_FORM: {
568
569 const char *zUrl;
570 const char *zMethod;
571 TGString cmd("");
572 // int result;
573 char zToken[50];
574
575 fFormStart = 0;
576 //form->fFormId = 0;
577
578 zUrl = p->MarkupArg("action", 0);
579 if (zUrl == 0) zUrl = fZBase;
581 if (zUrl == 0) zUrl = StrDup("");
582 zMethod = p->MarkupArg("method", "GET");
583 snprintf(zToken, 50, " %d form ", form->fFormId);
584 cmd.Append("Form:");
585 cmd.Append(zToken);
586 cmd.Append(zUrl);
587 cmd.Append(" ");
588 cmd.Append(zMethod);
589 cmd.Append(" { ");
591 cmd.Append("} ");
592 /* result = */ FormCreate(form, zUrl, cmd.GetString());
593 delete[] zUrl;
594
595 /*if (result)*/ fFormStart = form;
596
597 break;
598 }
599
600 case Html_EndFORM:
601 ((TGHtmlRef *)p)->fPOther = fFormStart;
603 fFormStart = 0;
604 break;
605
606 case Html_H1:
607 case Html_H2:
608 case Html_H3:
609 case Html_H4:
610 case Html_H5:
611 case Html_H6:
612 if (!fInTr) paraAlign = ALIGN_None;
613 i = (p->fType - Html_H1) / 2 + 1;
614 if (i >= 1 && i <= 6) {
616 }
617 style.fFont = BoldFont(style.fFont);
618 style.fAlign = p->GetAlignment(style.fAlign);
620 break;
621
622 case Html_EndH1:
623 case Html_EndH2:
624 case Html_EndH3:
625 case Html_EndH4:
626 case Html_EndH5:
627 case Html_EndH6:
630 break;
631
632 case Html_HR:
634 style.fAlign = p->GetAlignment(ALIGN_None);
635 useNextStyle = 1;
636 break;
637
638 case Html_I:
639 style.fFont = ItalicFont(style.fFont);
641 break;
642
643 case Html_IMG:
644 if (style.fFlags & STY_Invisible) break;
645 ((TGHtmlImageMarkup *)p)->fPImage = GetImage((TGHtmlImageMarkup *) p);
646 break;
647
648 case Html_OPTION:
649 break;
650
651 case Html_INPUT:
652 ((TGHtmlInput *)p)->fPForm = fFormStart;
653 ////ControlSize((TGHtmlInput *) p);
654 break;
655
656 case Html_KBD:
657 style.fFont = CWFont(style.fFont);
659 break;
660
661 case Html_LI:
662 if (fInnerList) {
663 TGHtmlLi *li = (TGHtmlLi *) p;
664 li->fLtype = fInnerList->fLtype;
665 if (fInnerList->fType == Html_OL) {
666 z = li->MarkupArg("value", 0);
667 if (z) {
668 int n = atoi(z);
669 if (n > 0) {
670 li->fCnt = n;
671 fInnerList->fCnt = n+1;
672 }
673 } else {
674 li->fCnt = fInnerList->fCnt++;
675 }
676 li->fLtype = li->GetOrderedListType(li->fLtype);
677 } else {
678 li->fLtype = li->GetUnorderedListType(li->fLtype);
679 }
680 } else {
681 p->fFlags &= ~HTML_Visible;
682 }
683 break;
684
685 case Html_MARQUEE:
686 style.fFlags |= STY_Invisible;
688 break;
689
690 case Html_NOBR:
691 style.fFlags |= STY_NoBreak;
693 break;
694
695 case Html_NOFRAMES:
696 if (0 /* has ProcessFrame()*/) {
698 nextStyle.fFlags |= STY_Invisible;
700 useNextStyle = 1;
701 } else {
703 }
704 break;
705
706 case Html_NOEMBED:
707 if (0 /* has ProcessScript() && HasScript */) {
709 nextStyle.fFlags |= STY_Invisible;
711 useNextStyle = 1;
712 } else {
714 }
715 break;
716
717 case Html_NOSCRIPT:
718 if (0 /* has ProcessScript() && HasScript */) {
720 nextStyle.fFlags |= STY_Invisible;
722 useNextStyle = 1;
723 } else {
725 }
726 break;
727
728 case Html_OL: {
730 list->fLPrev = fInnerList;
731 list->fLtype = list->GetOrderedListType(LI_TYPE_Enum_1);
732 list->fCnt = 1;
733 z = list->MarkupArg("start", 0);
734 if (z) {
735 int n = atoi(z);
736 if (n > 0) list->fCnt = n;
737 }
738 list->fCompact = (fInnerList != 0 || list->MarkupArg("compact", 0) != 0);
739 fInnerList = list;
740 break;
741 }
742
743 case Html_P:
744 paraAlign = p->GetAlignment(ALIGN_None);
745 break;
746
747 case Html_EndP:
749 break;
750
751 case Html_PRE:
752 case Html_LISTING:
753 case Html_XMP:
754 case Html_PLAINTEXT:
756 style.fFont = CWFont(style.fFont);
757 style.fFlags |= STY_Preformatted;
759 break;
760
761 case Html_EndPRE:
762 case Html_EndLISTING:
763 case Html_EndXMP:
765 break;
766
767 case Html_S:
768 style.fFlags |= STY_StrikeThru;
770 break;
771
772 case Html_SCRIPT: {
773 char *result;
774 result = ProcessScript((TGHtmlScript *) p); // fZText[script->nStart .. script->nScript]
775 if (result) {
776 TGHtmlElement *b2 = p->fPNext, *b3, *e1 = p, *e2 = b2, *e3;
777 if (e2) while (e2->fPNext) e2 = e2->fPNext;
779 if (e2 && e2 != p && ((e3 = b3 = e2->fPNext))) {
780 while (e3->fPNext) e3 = e3->fPNext;
781 e1->fPNext = b3;
782 e2->fPNext = 0; b2->fPPrev = e3;
783 e3->fPNext = b2; b3->fPPrev = e1;
784 }
785 delete[] result;
786 }
788 style.fFlags |= STY_Invisible;
789 useNextStyle = 1;
790 break;
791 }
792
793 case Html_SELECT:
794 ((TGHtmlInput *)p)->fPForm = fFormStart;
795 nextStyle.fFlags |= STY_Invisible;
796 useNextStyle = 1;
799 break;
800
801 case Html_EndSELECT:
804 ((TGHtmlRef *)p)->fPOther = fFormElemStart;
805 MakeInvisible(((TGHtmlRef *)p)->fPOther, p);
806 } else {
807 ((TGHtmlRef *)p)->fPOther = 0;
808 }
809 fFormElemStart = 0;
810 break;
811
812 case Html_STRIKE:
815 break;
816
817 case Html_STYLE:
818 // Ignore style sheets
819 break;
820
821 case Html_SAMP:
822 style.fFont = CWFont(style.fFont);
824 break;
825
826 case Html_SMALL:
827 ScaleFont(&style, -1);
829 break;
830
831 case Html_STRONG:
832 style.fFont = BoldFont(style.fFont);
834 break;
835
836 case Html_SUB:
837 ScaleFont(&style, -1);
838 if (style.fSubscript > -6 ) style.fSubscript--;
840 break;
841
842 case Html_SUP:
843 ScaleFont(&style, -1);
844 if (style.fSubscript < 6) style.fSubscript++;
846 break;
847
848 case Html_TABLE:
851 if (style.fFlags & STY_Preformatted) {
853 style.fFlags |= STY_Preformatted;
854 }
855 nextStyle.fAlign = ALIGN_Left;
856 z = p->MarkupArg("bgcolor", 0);
857 if (z && *z && !fOverrideColors) {
858 style.fBgcolor = nextStyle.fBgcolor = GetColorByName(z);
859 style.fExpbg = 1;
860// } else {
861// nextStyle.fBgcolor = COLOR_Background;
862 }
865 useNextStyle = 1;
866 fInTd = 0;
867 fInTr = 0;
868 break;
869
870 case Html_EndTABLE:
872 if (fInTd) {
874 fInTd = 0;
875 }
876 if (fInTr) {
878 fInTr = 0;
879 }
880 style = PopStyleStack(p->fType);
881 break;
882
883 case Html_TD:
885 fInTd = 1;
886 paraAlign = p->GetAlignment(rowAlign);
887 z = p->MarkupArg("bgcolor", 0);
888 if (z && *z && !fOverrideColors) {
889 style.fBgcolor = GetColorByName(z);
890 style.fExpbg = 1;
891 }
894 break;
895
896 case Html_TEXTAREA:
897 ((TGHtmlInput *)p)->fPForm = fFormStart;
899 nextStyle.fFlags |= STY_Invisible;
902 useNextStyle = 1;
903 break;
904
905 case Html_EndTEXTAREA:
908 ((TGHtmlRef *)p)->fPOther = fFormElemStart;
909 } else {
910 ((TGHtmlRef *)p)->fPOther = 0;
911 }
912 fFormElemStart = 0;
913 break;
914
915 case Html_TH:
916 //paraAlign = p->GetAlignment(rowAlign);
918 paraAlign = p->GetAlignment(ALIGN_Center);
919 style.fFont = BoldFont(style.fFont);
920 z = p->MarkupArg("bgcolor", 0);
921 if (z && *z && !fOverrideColors) {
922 style.fBgcolor = GetColorByName(z);
923 style.fExpbg = 1;
924 }
926 fInTd = 1;
927 break;
928
929 case Html_TR:
930 if (fInTd) {
932 fInTd = 0;
933 }
934 if (fInTr) {
936 }
937 rowAlign = p->GetAlignment(ALIGN_None);
938 z = p->MarkupArg("bgcolor", 0);
939 if (z && *z && !fOverrideColors) {
940 style.fBgcolor = GetColorByName(z);
941 style.fExpbg = 1;
942 }
945 fInTr = 1;
946 break;
947
948 case Html_EndTR:
949 if (fInTd) {
951 fInTd = 0;
952 }
954 fInTr = 0;
957 break;
958
959 case Html_EndTD:
960 case Html_EndTH:
962 fInTd = 0;
964 //rowAlign = ALIGN_None;
965 break;
966
967 case Html_TITLE:
968 style.fFlags |= STY_Invisible;
970 break;
971
972 case Html_TT:
973 style.fFont = CWFont(style.fFont);
975 break;
976
977 case Html_U:
978 style.fFlags |= STY_Underline;
980 break;
981
982 case Html_VAR:
983 style.fFont = ItalicFont(style.fFont);
985 break;
986
987 default:
988 break;
989 }
990
991 p->fStyle = style;
992 p->fStyle.fFlags |= fAnchorFlags | fInDt;
993 if (paraAlign != ALIGN_None) {
994 p->fStyle.fAlign = paraAlign;
995 }
996 if (useNextStyle) {
998 style.fExpbg = 0;
999 useNextStyle = 0;
1000 }
1001
1003 ("Style font=%02d color=%02d bg=%02d "
1004 "align=%d flags=0x%04x token=%s\n",
1005 p->fStyle.fFont, p->fStyle.fColor, p->fStyle.fBgcolor,
1006 p->fStyle.fAlign, p->fStyle.fFlags, DumpToken(p)));
1007
1008 p = p->fPNext;
1009 }
1010
1011 // Copy state information back into the TGHtml object for safe keeping.
1012
1015
1017}
1018
1019////////////////////////////////////////////////////////////////////////////////
1020/// Set background picture of a html table.
1021
1023{
1024 const char *z;
1025
1026 z = p->MarkupArg("background", 0);
1027 if (!z) return;
1028
1029 char *z1 = ResolveUri(z);
1030 TImage *img = LoadImage(z1, 0, 0);
1031 delete [] z1;
1032
1033 switch (p->fType) {
1034 case Html_TABLE: {
1035 TGHtmlTable *table = (TGHtmlTable *) p;
1036 if (table->fBgImage) delete table->fBgImage;
1037 table->fBgImage = img;
1038 break;
1039 }
1040 case Html_TR: {
1041 TGHtmlRef *ref = (TGHtmlRef *) p;
1042 if (ref->fBgImage) delete ref->fBgImage;
1043 ref->fBgImage = img;
1044 break;
1045 }
1046 case Html_TH:
1047 case Html_TD: {
1048 TGHtmlCell *cell = (TGHtmlCell *) p;
1049 if (cell->fBgImage) delete cell->fBgImage;
1050 cell->fBgImage = img;
1051 break;
1052 }
1053 default:
1054 if (img) delete img;
1055 break;
1056 }
1057}
1058
1059////////////////////////////////////////////////////////////////////////////////
1060/// Compute the size of all elements in the widget. Assume that a style has
1061/// already been assigned to all elements.
1062///
1063/// Some of the elements might have already been sized. Refer to the
1064/// fLastSized and only compute sizes for elements that follow this one. If
1065/// fLastSized is 0, then size everything.
1066///
1067/// This routine only computes the sizes of individual elements. The size of
1068/// aggregate elements (like tables) are computed separately.
1069///
1070/// The HTML_Visible flag is also set on every element that results in ink on
1071/// the page.
1072///
1073/// This routine may invoke a callback procedure which could delete the HTML
1074/// widget.
1075
1077{
1079 int iFont = -1;
1080 TGFont *font=0;
1081 int spaceWidth = 0;
1083 const char *z;
1084 int stop = 0;
1085
1086 if (fPFirst == 0) return;
1087
1088 if (fLastSized == 0) {
1089 p = fPFirst;
1090 } else {
1091 p = fLastSized->fPNext;
1092 }
1093
1094 // coverity[dead_error_line]
1095 for (; !stop && p; p = p ? p->fPNext : 0) {
1096 if (p->fStyle.fFlags & STY_Invisible) {
1097 p->fFlags &= ~HTML_Visible;
1098 continue;
1099 }
1100 if (iFont != (int)p->fStyle.fFont) {
1101 iFont = p->fStyle.fFont;
1102 font = GetFont(iFont);
1104 spaceWidth = 0;
1105 }
1106 if (!font)
1107 continue;
1108 switch (p->fType) {
1109 case Html_Text: {
1111 text->fW = font->TextWidth(text->fZText, p->fCount);
1112 p->fFlags |= HTML_Visible;
1113 text->fDescent = fontMetrics.fDescent;
1114 text->fAscent = fontMetrics.fAscent;
1115 if (spaceWidth == 0) spaceWidth = font->TextWidth(" ", 1);
1116 text->fSpaceWidth = spaceWidth;
1117 break;
1118 }
1119
1120 case Html_Space: {
1122 if (spaceWidth == 0) spaceWidth = font->TextWidth(" ", 1);
1123 space->fW = spaceWidth;
1124 space->fDescent = fontMetrics.fDescent;
1125 space->fAscent = fontMetrics.fAscent;
1126 p->fFlags &= ~HTML_Visible;
1127 break;
1128 }
1129
1130 case Html_TD:
1131 case Html_TH: {
1132 TGHtmlCell *cell = (TGHtmlCell *) p;
1133 z = p->MarkupArg("rowspan", "1");
1134 cell->fRowspan = z ? atoi(z) : 1;
1135 z = p->MarkupArg("colspan", "1");
1136 cell->fColspan = z ? atoi(z) : 1;
1137 p->fFlags |= HTML_Visible;
1138 break;
1139 }
1140
1141 case Html_LI: {
1142 TGHtmlLi *li = (TGHtmlLi *) p;
1143 li->fDescent = fontMetrics.fDescent;
1144 li->fAscent = fontMetrics.fAscent;
1145 p->fFlags |= HTML_Visible;
1146 break;
1147 }
1148
1149 case Html_IMG: {
1151 z = p->MarkupArg("usemap", 0);
1152 if (z && *z == '#') {
1153 image->fPMap = GetMap(z+1);
1154 } else {
1155 image->fPMap = 0;
1156 }
1157 p->fFlags |= HTML_Visible;
1158 image->fRedrawNeeded = 0;
1159 image->fTextAscent = fontMetrics.fAscent;
1160 image->fTextDescent = fontMetrics.fDescent;
1161 image->fAlign = GetImageAlignment(p);
1162 if (image->fPImage == 0) {
1163 image->fAscent = fontMetrics.fAscent;
1164 image->fDescent = fontMetrics.fDescent;
1165 image->fZAlt = p->MarkupArg("alt", "<image>");
1166 if (image->fZAlt == 0) image->fZAlt = "<image>";
1167 image->fW = font->TextWidth(image->fZAlt, strlen(image->fZAlt));
1168 } else {
1169 int w, h;
1170 image->fINext = image->fPImage->fPList;
1171 image->fPImage->fPList = image;
1172 w = image->fPImage->fImage->GetWidth();
1173 h = image->fPImage->fImage->GetHeight();
1174 image->fH = h;
1175 image->fW = w;
1176 image->fAscent = h / 2;
1177 image->fDescent = h - image->fAscent;
1178 }
1179 if ((z = p->MarkupArg("width", 0)) != 0) {
1180 int w = atoi(z);
1181 if (z[strlen(z)-1] == '%') w = 0; //// -- HP
1182 if (w > 0) image->fW = w;
1183 }
1184 if ((z = p->MarkupArg("height", 0)) != 0) {
1185 int h = atoi(z);
1186 if (h > 0) image->fH = h;
1187 }
1188
1189#if 1 // --HP
1190 if (image->fPImage == 0 && !*image->fZAlt) {
1191 image->fAscent = image->fH / 2;
1192 image->fDescent = image->fH - image->fAscent;
1193 }
1194#endif
1195 break;
1196 }
1197
1198 case Html_TABLE:
1199 p->fFlags |= HTML_Visible;
1200 break;
1201
1202 case Html_HR:
1203 p->fFlags |= HTML_Visible;
1204 break;
1205
1206 case Html_APPLET:
1207 case Html_EMBED:
1208 case Html_INPUT: {
1210 input->fTextAscent = fontMetrics.fAscent;
1211 input->fTextDescent = fontMetrics.fDescent;
1212 stop = ControlSize(input);
1213 break;
1214 }
1215
1216 case Html_SELECT:
1217 case Html_TEXTAREA: {
1219 input->fTextAscent = fontMetrics.fAscent;
1220 input->fTextDescent = fontMetrics.fDescent;
1221 break;
1222 }
1223
1224 case Html_EndSELECT:
1225 case Html_EndTEXTAREA: {
1226 TGHtmlRef *ref = (TGHtmlRef *) p;
1227 if (ref->fPOther) {
1228 ((TGHtmlInput *)ref->fPOther)->fPEnd = p;
1229 stop = ControlSize((TGHtmlInput *) ref->fPOther);
1230 }
1231 break;
1232 }
1233
1234 default:
1235 p->fFlags &= ~HTML_Visible;
1236 break;
1237 }
1238 }
1239
1240 if (p) {
1241 fLastSized = p;
1242 } else {
1244 }
1245}
@ kFillTiled
Definition GuiTypes.h:51
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static void ScaleFont(SHtmlStyle_t *pStyle, int delta)
Change the font size on the given style by the delta-amount given.
static int * GetCoords(const char *str, int *nptr)
Returns coordinates of string str.
#define Html_TypeCount
@ Html_EndBODY
@ Html_NOEMBED
@ Html_SUP
@ Html_H3
@ Html_MARQUEE
@ Html_EndH4
@ Html_FORM
@ Html_U
@ Html_DFN
@ Html_COMMENT
@ Html_EndTT
@ Html_EndTH
@ Html_EndMENU
@ Html_BODY
@ Html_EM
@ Html_BLOCKQUOTE
@ Html_HR
@ Html_STRIKE
@ Html_EndTABLE
@ Html_I
@ Html_KBD
@ Html_DL
@ Html_EndTEXTAREA
@ Html_TEXTAREA
@ Html_XMP
@ Html_EndNOSCRIPT
@ Html_DT
@ Html_NOBR
@ Html_TD
@ Html_EMBED
@ Html_STYLE
@ Html_CENTER
@ Html_TITLE
@ Html_SCRIPT
@ Html_LI
@ Html_EndBLOCKQUOTE
@ Html_EndSELECT
@ Html_EndSTRIKE
@ Html_EndSUB
@ Html_EndNOEMBED
@ Html_CAPTION
@ Html_EndLISTING
@ Html_AREA
@ Html_S
@ Html_EndDFN
@ Html_EndADDRESS
@ Html_UL
@ Html_LISTING
@ Html_TABLE
@ Html_EndUL
@ Html_EndOL
@ Html_NOFRAMES
@ Html_PLAINTEXT
@ Html_EndS
@ Html_EndDIR
@ Html_OPTION
@ Html_EndI
@ Html_H2
@ Html_EndSTRONG
@ Html_EndNOBR
@ Html_APPLET
@ Html_EndSUP
@ Html_EndNOFRAMES
@ Html_TH
@ Html_EndFORM
@ Html_EndFONT
@ Html_EndTD
@ Html_MENU
@ Html_CODE
@ Html_TR
@ Html_H6
@ Html_ADDRESS
@ Html_DIV
@ Html_EndB
@ Html_Space
@ Html_EndVAR
@ Html_EndDT
@ Html_EndH3
@ Html_SAMP
@ Html_SELECT
@ Html_H5
@ Html_Text
@ Html_H1
@ Html_EndDIV
@ Html_VAR
@ Html_EndBASEFONT
@ Html_OL
@ Html_A
@ Html_P
@ Html_B
@ Html_IMG
@ Html_CITE
@ Html_EndAPPLET
@ Html_EndDL
@ Html_EndCAPTION
@ Html_BIG
@ Html_SUB
@ Html_EndKBD
@ Html_EndCODE
@ Html_NOSCRIPT
@ Html_EndCITE
@ Html_DIR
@ Html_EndSMALL
@ Html_H4
@ Html_EndH1
@ Html_EndH2
@ Html_EndH5
@ Html_STRONG
@ Html_BASE
@ Html_FONT
@ Html_DD
@ Html_EndBIG
@ Html_EndXMP
@ Html_EndDD
@ Html_EndP
@ Html_EndH6
@ Html_EndA
@ Html_EndPRE
@ Html_EndTITLE
@ Html_PRE
@ Html_TT
@ Html_INPUT
@ Html_EndMAP
@ Html_EndMARQUEE
@ Html_EndCOMMENT
@ Html_EndSAMP
@ Html_MAP
@ Html_SMALL
@ Html_EndCENTER
@ Html_EndU
@ Html_BASEFONT
@ Html_EndTR
@ Html_EndEM
#define STYLER_RUNNING
Definition TGHtml.h:1338
#define HTML_MAP_CIRCLE
Definition TGHtml.h:465
#define LI_TYPE_Bullet2
Definition TGHtml.h:440
#define COLOR_Unvisited
Definition TGHtml.h:198
#define HTML_Visible
Definition TGHtml.h:275
#define ALIGN_Left
Definition TGHtml.h:209
#define STY_Invisible
Definition TGHtml.h:240
#define HTML_MAP_RECT
Definition TGHtml.h:464
#define LI_TYPE_Bullet1
Definition TGHtml.h:439
#define LI_TYPE_Enum_1
Definition TGHtml.h:442
#define CWFont(X)
Definition TGHtml.h:170
#define HTML_MAP_POLY
Definition TGHtml.h:466
#define STY_NoBreak
Definition TGHtml.h:237
#define CANT_HAPPEN
Definition TGHtml.h:60
#define COLOR_Background
Definition TGHtml.h:201
#define ItalicFont(X)
Definition TGHtml.h:169
#define STY_DT
Definition TGHtml.h:239
#define BoldFont(X)
Definition TGHtml.h:168
#define STY_Anchor
Definition TGHtml.h:238
#define ALIGN_Center
Definition TGHtml.h:211
#define STY_StrikeThru
Definition TGHtml.h:235
#define N_FONT_SIZE
Definition TGHtml.h:165
#define STY_Underline
Definition TGHtml.h:236
#define STY_Preformatted
Definition TGHtml.h:234
#define FontFamily(X)
Definition TGHtml.h:172
#define HtmlTrace_Style
Definition TGHtml.h:96
#define LI_TYPE_Bullet3
Definition TGHtml.h:441
#define FontSize(X)
Definition TGHtml.h:171
#define COLOR_Normal
Definition TGHtml.h:197
#define TRACE(Flag, Args)
Definition TGHtml.h:121
#define NormalFont(X)
Definition TGHtml.h:167
#define ALIGN_None
Definition TGHtml.h:212
#define COLOR_Visited
Definition TGHtml.h:199
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
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 result
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 Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t style
Option_t Option_t TPoint TPoint const char text
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2557
#define gVirtualX
Definition TVirtualX.h:337
#define snprintf
Definition civetweb.c:1540
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
void GetFontMetrics(FontMetrics_t *m) const
Get font metrics.
Definition TGFont.cxx:286
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
GContext_t GetGC() const
Definition TGGC.h:41
Html_u8_t fFlags
Definition TGHtml.h:266
Html_u8_t fType
Definition TGHtml.h:265
TGHtmlElement * fPPrev
Definition TGHtml.h:263
TGHtmlElement * fPNext
Definition TGHtml.h:262
TGHtmlElement * fPEnd
Definition TGHtml.h:643
TGHtmlListStart * fLPrev
Definition TGHtml.h:460
Html_u8_t fLtype
Definition TGHtml.h:456
Html_u16_t fCnt
Definition TGHtml.h:458
Html_u8_t fCompact
Definition TGHtml.h:457
const char * MarkupArg(const char *tag, const char *zDefault) override
Lookup an argument in the given markup with the name given.
TImage * fBgImage
Definition TGHtml.h:412
TGHtmlElement * fPOther
Definition TGHtml.h:411
Html_u8_t fDescent
Definition TGHtml.h:311
Html_u8_t fAscent
Definition TGHtml.h:310
Html_16_t fW
Definition TGHtml.h:309
TImage * fBgImage
Definition TGHtml.h:370
TGHtmlElement * GetMap(const char *name)
Returns html map element.
Definition TGHtml.cxx:1593
int fParaAlignment
Definition TGHtml.h:1198
virtual int FormCreate(TGHtmlForm *, const char *, const char *)
Definition TGHtml.h:946
const char * fZBase
Definition TGHtml.h:1268
int fUnderlineLinks
Definition TGHtml.h:1251
void TokenizerAppend(const char *text)
Append text to the tokenizer engine.
TGHtmlElement * fPFirst
Definition TGHtml.h:1136
void AddStyle(TGHtmlElement *p)
This routine adds information to the input texts that doesn't change when the display is resized or w...
virtual char * ProcessScript(TGHtmlScript *)
Definition TGHtml.h:958
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
ColorStruct_t * fApColor[32]
Definition TGHtml.h:1232
int fAnchorFlags
Definition TGHtml.h:1200
TGHtmlElement * fLastSized
Definition TGHtml.h:1140
int GetColorByName(const char *zColor)
This routine returns an index between 0 and N_COLOR-1 which indicates which ColorStruct_t structure i...
Definition TGHtml.cxx:1629
int fFlags
Definition TGHtml.h:1278
SHtmlStyleStack_t * fStyleStack
Definition TGHtml.h:1197
TGHtmlListStart * fInnerList
Definition TGHtml.h:1208
int fOverrideColors
Definition TGHtml.h:1250
void AppendArglist(TGString *str, TGHtmlMarkupElement *pElem)
Append all the arguments of the given markup to the given TGString.
void TableBgndImage(TGHtmlElement *p)
Set background picture of a html table.
virtual TImage * LoadImage(const char *uri, int w=0, int h=0)
This is the default LoadImage() procedure.
void MakeInvisible(TGHtmlElement *p_first, TGHtmlElement *p_last)
Add the STY_Invisible style to every token between p_first and p_last.
ColorStruct_t * AllocColor(const char *name)
Allocate system color by name.
Definition TGHtml.cxx:272
int GetImageAlignment(TGHtmlElement *p)
Find the alignment for an image.
int fRowAlignment
Definition TGHtml.h:1199
int fInTr
Definition TGHtml.h:1202
int GetLinkColor(const char *zURL)
For the markup <a href=XXX>, find out if the URL has been visited before or not.
TGHtmlAnchor * fAnchorStart
Definition TGHtml.h:1204
void Sizer()
Compute the size of all elements in the widget.
TGHtmlElement * fPLast
Definition TGHtml.h:1137
SHtmlStyle_t PopStyleStack(int tag)
Pop a rendering style off of the stack.
int fInTd
Definition TGHtml.h:1203
virtual int IsVisited(const char *)
Definition TGHtml.h:924
virtual char * ResolveUri(const char *uri)
This function resolves the specified URI and returns the result in a newly allocated string.
void PushStyleStack(int tag, SHtmlStyle_t style)
Push a new rendering style onto the stack.
int fOverrideFonts
Definition TGHtml.h:1249
TImage * fBgImage
Definition TGHtml.h:1246
int ControlSize(TGHtmlInput *p)
This routine implements the Sizer() function for <INPUT>, <SELECT> and <TEXTAREA> markup.
int fInDt
Definition TGHtml.h:1201
char * DumpToken(TGHtmlElement *p)
For debugging purposes, print information about a token.
SHtmlStyle_t GetCurrentStyle()
Get the current rendering style.
TGHtmlImage * GetImage(TGHtmlImageMarkup *p)
Given an <IMG> markup, find or create an appropriate TGHtmlImage object and return a pointer to that ...
TGHtmlInput * fFormElemStart
Definition TGHtml.h:1206
TGHtmlForm * fFormStart
Definition TGHtml.h:1205
char * fZBaseHref
Definition TGHtml.h:1269
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
void SetBackgroundColor(Pixel_t) override
Set background color of the canvas frame.
Definition TGView.cxx:590
TGViewFrame * fCanvas
frame containing the text
Definition TGView.h:42
void SetBackgroundPixmap(Pixmap_t p) override
Set backgound pixmap.
Definition TGView.cxx:600
TGGC fWhiteGC
graphics context used for scrolling generates GraphicsExposure events
Definition TGView.h:46
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:248
An abstract interface to image processing library.
Definition TImage.h:29
const Int_t n
Definition legend1.C:16
Graphics context structure.
Definition GuiTypes.h:224
SHtmlStyle_t fStyle
Definition TGHtml.h:736
unsigned int fFont
Definition TGHtml.h:145