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