Debian Codegraph @

src/af/xap/xp/xap_FontPreview.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 * Copyright (C) 2009 Hubert Figuiere
4 *
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.
9 *
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.
14 *
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
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301 USA.
19 */
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "ut_string.h"
25 #include "ut_debugmsg.h"
26 #include "xap_FontPreview.h"
27
28 // standard font preview string
29 #define PREVIEW_ENTRY_DEFAULT_STRING "AaBbYyZz"
30
31 XAP_FontPreview::XAP_FontPreview()
32 : m_width(PREVIEW_WIDTH)
33 , m_height(PREVIEW_HEIGHT)
34 , m_pFontPreview(NULL)
35 {
36 UT_UCS4_cloneString_char (&m_drawString, PREVIEW_ENTRY_DEFAULT_STRING);
37 }
38
39 XAP_FontPreview::~XAP_FontPreview(void)
40 {
41 FREEP(m_drawString);
42 DELETEP(m_pFontPreview);
43 }
44
45 void XAP_FontPreview::_createFontPreviewFromGC(GR_Graphics * gc,
46 UT_uint32 width,
47 UT_uint32 height)
48 {
49 UT_ASSERT(gc);
50 UT_DEBUGMSG(("SEVIOR!!!!!!!!!!! font priview created!!!!!\n"));
51 m_pFontPreview = new XAP_Preview_FontPreview(gc,NULL);
52 UT_return_if_fail(m_pFontPreview);
53
54 m_pFontPreview->setDrawString(m_drawString);
55 m_pFontPreview->setVecProperties(&m_mapProps);
56 m_pFontPreview->setWindowSize(width, height);
57 m_width = gc->tlu(width);
58 m_height = gc->tlu(height);
59 addOrReplaceVecProp("font-size","36pt");
60 }
61
62 void XAP_FontPreview::addOrReplaceVecProp(const std::string & pszProp,
63 const std::string & pszVal)
64 {
65 m_mapProps[pszProp] = pszVal;
66 }
67
68 void XAP_FontPreview::setFontFamily(const gchar * pFontFamily)
69 {
70 addOrReplaceVecProp("font-family",pFontFamily);
71 }
72
73 void XAP_FontPreview::setText(const gchar * pFontFamily)
74 {
75 UT_return_if_fail(pFontFamily);
76 FREEP(m_drawString);
77 UT_UCS4_cloneString_char (&m_drawString, pFontFamily);
78 m_pFontPreview->setDrawString(m_drawString);
79 }
80
81 void XAP_FontPreview::draw()
82 {
83 if (m_pFontPreview)
84 m_pFontPreview->draw();
85 }
86