1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006 - Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Class for drawing formatted text on a device context.
29 ~CHTMLFormatter(void);
31 * Draws formatted text to the given device context with the given font. The following formatting
32 * parameters are available:\n
33 * - \c \<b> \e text \c \</b> \t draws the text in bold
34 * - \c \<u> \e text \c \</u> \t draws the text underlined
35 * - \c \<i> \e text \c \</u> \t draws the text in italic
36 * - \c \<s> \e text \c \</u> \t draws the text with strikeout
38 * - \c \<ct=0x123456> \e text \c \</ct> \t draws the text in the given color. The value is in RGB format.
39 * - \c \<cb=0x123456> \e text \c \</cb> \t draws the background of the text in the given color. The value is in RGB format.
41 * - \c \<al> \e text \c \</al> \t aligns the text to the left
42 * - \c \<ac> \e text \c \</ac> \t aligns the text to the center
43 * - \c \<ar> \e text \c \</ar> \t aligns the text to the right
45 * - \c \<hr=50%> \t draws a horizontal line with 50% of the whole width
46 * - \c \<hr=100> \t draws a horizontal line with 100 pixels length
48 * - \c \<a=http://something.com> \e text \c \</a> \t the text is marked as a link in the internal link list.
50 * also the common control codes \\n, \\t, \\r are recognized.
52 * An example of usage:
54 * CHTMLFormatter formatter;
56 * CString strInfo = _T("<ct=0x0000FF><<b></ct>text<ct=0x0000FF><</b></ct><t=8> - <b>Bold text</b>\n");
57 * strInfo += _T("<ct=0x0000FF><<i></ct>text<ct=0x0000FF><</i></ct><t=8> - <i>Italic text</i>\n");
58 * strInfo += _T("<ct=0x0000FF><<u></ct>text<ct=0x0000FF><</u></ct><t=8> - <u>Underline text</u>\n");
59 * strInfo += _T("<ct=0x0000FF><<s></ct>text<ct=0x0000FF><</s></ct><t=8> - <s>Strikeout text</s>\n");
60 * strInfo += _T("<ct=0x0000FF><<ct=0x0000FF></ct>text<ct=0x0000FF><</ct></ct><t=5> - <ct=0x0000FF>Red text</ct>\n");
61 * strInfo += _T("<ct=0x0000FF><<cb=0xFFFF00></ct>text<ct=0x0000FF><</cb></ct><t=5> - <cb=0xFFFF00>Cyan background</cb>\n");
62 * strInfo += _T("<ct=0x0000FF><<t></ct><t=10> - Tabulation\n");
63 * strInfo += _T("<ct=0x0000FF><<hr=80%></ct><t=9> - Horizontal line\n");
64 * strInfo += _T("<hr=80%>\n");
65 * strInfo += _T("<ct=0x0000FF><<al></ct><t=10> - Left align\n");
66 * strInfo += _T("<ct=0x0000FF><<ac></ct><t=10> - Center align\n");
67 * strInfo += _T("<ct=0x0000FF><<ar></ct><t=10> - Right align\n");
68 * strInfo += _T("<ct=0x0000FF><<a=http://somelink.com><<u></ct>link<ct=0x0000FF><</u><</a></ct><t> - Link\n");
70 * formatter.DrawHTML(pDC, rect, strInfo, font);
72 * this example produces the following picture:
73 * \image html "htmlformatter.png"
75 * \remarks please be aware that this is a lightweight class and not a real HTML printer. Only very basic
76 * tags are available and folding tags is also very limited.\n
77 * The link tag also has restrictions:
78 * - a link must not span more than one line of text
79 * - inner tags are allowed, but only for the whole link text. I.e. "<a=http://something.com><b>this</b> is my link</a>" is not allowed!
81 * \param pDC the device context to draw the text on
82 * \param rect the rectangle to draw the text within
83 * \param str the string to draw
84 * \param font the font to draw the text with
85 * \param bCalculate if set to TRUE, then no drawing is done but only the size of the required rectangle to fit
86 * the text is calculated.
87 * \return The required size of the rectangle to fit the text in.
89 CSize
DrawHTML(CDC
* pDC
, CRect rect
, CString str
, LOGFONT font
, BOOL bCalculate
= FALSE
);
92 * Checks if a given point is over a hyperlink text
94 BOOL
IsPointOverALink(CPoint pt
);
97 * Returns the URL of the link or an empty string if the point is not over a hyperlink text.
99 CString
GetLinkForPoint(CPoint pt
);
102 typedef enum{ NONE
= 0,
116 typedef enum{ BEGIN_TAG
= 0,
128 enum{ ALIGN_LEFT
= 0,
133 * Draws a horizontal line to the device context
134 * \param pDC the device context to draw to
135 * \param xStart the starting x coordinate of the line
136 * \param xEnd the ending x coordinate of the line
137 * \param y the y coordinate of the line
139 static void DrawHorzLine(CDC
* pDC
, int xStart
, int xEnd
, int y
);
142 CArray
<CRect
, CRect
&> m_arLinkRects
;
143 CStringArray m_arLinkURLs
;