Debian Codegraph @

src/lib/WPSFont.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent ([email protected])
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
13 * Copyright (C) 2004 Marc Maurer ([email protected])
14 * Copyright (C) 2003-2005 William Lachance ([email protected])
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26 #include <librevenge/librevenge.h>
27
28 #include "libwps_internal.h"
29 #include "libwps_tools_win.h"
30
31 #include "WPSListener.h"
32 #include "WPSFont.h"
33
34 std::ostream &operator<<(std::ostream &o, WPSFont const &ft)
35 {
36 uint32_t flags = ft.m_attributes;
37 if (!ft.m_name.empty())
38 o << "nam='" << ft.m_name.cstr() << "',";
39 if (ft.m_size > 0) o << "sz=" << ft.m_size << ",";
40
41 if (flags) o << "fl=";
42 if (flags&WPS_BOLD_BIT) o << "b:";
43 if (flags&WPS_ITALICS_BIT) o << "it:";
44 if (flags&WPS_UNDERLINE_BIT) o << "underL:";
45 if (flags&WPS_OVERLINE_BIT) o << "overL:";
46 if (flags&WPS_EMBOSS_BIT) o << "emboss:";
47 if (flags&WPS_SHADOW_BIT) o << "shadow:";
48 if (flags&WPS_OUTLINE_BIT) o << "outline:";
49 if (flags&WPS_DOUBLE_UNDERLINE_BIT) o << "2underL:";
50 if (flags&WPS_STRIKEOUT_BIT) o << "strikeout:";
51 if (flags&WPS_SMALL_CAPS_BIT) o << "smallCaps:";
52 if (flags&WPS_ALL_CAPS_BIT) o << "allCaps:";
53 if (flags&WPS_HIDDEN_BIT) o << "hidden:";
54 if (flags&WPS_SMALL_PRINT_BIT) o << "consended:";
55 if (flags&WPS_LARGE_BIT) o << "extended:";
56 if (flags&WPS_SUPERSCRIPT_BIT) o << "superS:";
57 if (flags&WPS_SUBSCRIPT_BIT) o << "subS:";
58 if (flags) o << ",";
59
60 if (ft.m_spacing<0)
61 o << "condensed=" << -ft.m_spacing << "pt,";
62 else if (ft.m_spacing>0)
63 o << "extended=" << ft.m_spacing << "pt,";
64 if (!ft.m_color.isBlack()) o << "col=" << ft.m_color << ",";
65 if (ft.m_extra.length()) o << "extra=" << ft.m_extra << ",";
66 return o;
67 }
68
69 WPSFont::~WPSFont()
70 {
71 }
72
73 bool WPSFont::operator==(WPSFont const &ft) const
74 {
75 if (m_size < ft.m_size || m_size > ft.m_size ||
76 m_attributes != ft.m_attributes || m_color != ft.m_color ||
77 m_spacing < ft.m_spacing || m_spacing > ft.m_spacing ||
78 m_languageId != ft.m_languageId)
79 return false;
80 if (m_name != ft.m_name || m_extra.compare(ft.m_extra))
81 return false;
82 return true;
83 }
84
85 void WPSFont::addTo(librevenge::RVNGPropertyList &propList) const
86 {
87 double fontSizeChange = 1.0;
88 switch (m_attributes& 0x0000001f)
89 {
90 case 0x01: // Extra large
91 fontSizeChange = 2.0;
92 break;
93 case 0x02: // Very large
94 fontSizeChange = 1.5;
95 break;
96 case 0x04: // Large
97 fontSizeChange = 1.2;
98 break;
99 case 0x08: // Small print
100 fontSizeChange = 0.8;
101 break;
102 case 0x10: // Fine print
103 fontSizeChange = 0.6;
104 break;
105 default: // Normal
106 fontSizeChange = 1.0;
107 break;
108 }
109
110 if (m_attributes & WPS_SUPERSCRIPT_BIT)
111 propList.insert("style:text-position", "super 58%");
112 else if (m_attributes & WPS_SUBSCRIPT_BIT)
113 propList.insert("style:text-position", "sub 58%");
114 if (m_attributes & WPS_ITALICS_BIT)
115 propList.insert("fo:font-style", "italic");
116 if (m_attributes & WPS_BOLD_BIT)
117 propList.insert("fo:font-weight", "bold");
118 if (m_attributes & WPS_STRIKEOUT_BIT)
119 propList.insert("style:text-line-through-type", "single");
120 if (m_attributes & WPS_DOUBLE_UNDERLINE_BIT)
121 propList.insert("style:text-underline-type", "double");
122 else if (m_attributes & WPS_UNDERLINE_BIT)
123 propList.insert("style:text-underline-type", "single");
124 if (m_attributes & WPS_OVERLINE_BIT)
125 propList.insert("style:text-overline-type", "single");
126 if (m_attributes & WPS_OUTLINE_BIT)
127 propList.insert("style:text-outline", "true");
128 if (m_attributes & WPS_SMALL_CAPS_BIT)
129 propList.insert("fo:font-variant", "small-caps");
130 if (m_attributes & WPS_BLINK_BIT)
131 propList.insert("style:text-blinking", "true");
132 if (m_attributes & WPS_SHADOW_BIT)
133 propList.insert("fo:text-shadow", "1pt 1pt");
134 if (m_attributes & WPS_HIDDEN_BIT)
135 propList.insert("text:display", "none");
136 if (m_attributes & WPS_ALL_CAPS_BIT)
137 propList.insert("fo:text-transform", "uppercase");
138 if (m_attributes & WPS_EMBOSS_BIT)
139 propList.insert("style:font-relief", "embossed");
140 else if (m_attributes & WPS_ENGRAVE_BIT)
141 propList.insert("style:font-relief", "engraved");
142
143 if (!m_name.empty())
144 propList.insert("style:font-name", m_name);
145 if (m_size>0)
146 propList.insert("fo:font-size", fontSizeChange*m_size, librevenge::RVNG_POINT);
147 if (m_spacing < 0 || m_spacing > 0)
148 propList.insert("fo:letter-spacing", m_spacing, librevenge::RVNG_POINT);
149
150 propList.insert("fo:color", m_color.str().c_str());
151
152 if (m_languageId < 0)
153 libwps_tools_win::Language::addLocaleName(0x409, propList);
154 if (m_languageId > 0)
155 libwps_tools_win::Language::addLocaleName(m_languageId, propList);
156 }
157
158 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */