/src/libreoffice/drawinglayer/source/tools/emfpstringformat.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <sal/log.hxx> |
21 | | #include <rtl/ustrbuf.hxx> |
22 | | #include "emfpstringformat.hxx" |
23 | | |
24 | | namespace emfplushelper |
25 | | { |
26 | | EMFPStringFormat::EMFPStringFormat() |
27 | 0 | : header(0) |
28 | 0 | , stringFormatFlags(0) |
29 | 0 | , language(0) |
30 | 0 | , stringAlignment(0) |
31 | 0 | , lineAlign(0) |
32 | 0 | , digitSubstitution(0) |
33 | 0 | , digitLanguage(0) |
34 | 0 | , firstTabOffset(0.0) |
35 | 0 | , hotkeyPrefix(0) |
36 | 0 | , leadingMargin(0.0) |
37 | 0 | , trailingMargin(0.0) |
38 | 0 | , tracking(1.0) |
39 | 0 | , trimming(0) |
40 | 0 | , tabStopCount(0) |
41 | 0 | , rangeCount(0) |
42 | 0 | { |
43 | 0 | } |
44 | | |
45 | | static OUString StringFormatFlags(sal_uInt32 flag) |
46 | 0 | { |
47 | 0 | OUStringBuffer sFlags; |
48 | | |
49 | | // These are extracted from enum in emfpstringformat.hxx |
50 | 0 | if (flag & StringFormatDirectionRightToLeft) |
51 | 0 | sFlags.append("StringFormatDirectionRightToLeft "); |
52 | |
|
53 | 0 | if (flag & StringFormatDirectionVertical) |
54 | 0 | sFlags.append("StringFormatDirectionVertical "); |
55 | |
|
56 | 0 | if (flag & StringFormatNoFitBlackBox) |
57 | 0 | sFlags.append("StringFormatNoFitBlackBox "); |
58 | |
|
59 | 0 | if (flag & StringFormatDisplayFormatControl) |
60 | 0 | sFlags.append("StringFormatDisplayFormatControl "); |
61 | |
|
62 | 0 | if (flag & StringFormatNoFontFallback) |
63 | 0 | sFlags.append("StringFormatNoFontFallback "); |
64 | |
|
65 | 0 | if (flag & StringFormatMeasureTrailingSpaces) |
66 | 0 | sFlags.append("StringFormatMeasureTrailingSpaces "); |
67 | |
|
68 | 0 | if (flag & StringFormatNoWrap) |
69 | 0 | sFlags.append("StringFormatNoWrap "); |
70 | |
|
71 | 0 | if (flag & StringFormatLineLimit) |
72 | 0 | sFlags.append("StringFormatLineLimit "); |
73 | |
|
74 | 0 | if (flag & StringFormatNoClip) |
75 | 0 | sFlags.append("StringFormatNoClip "); |
76 | |
|
77 | 0 | if (flag & StringFormatBypassGDI) |
78 | 0 | sFlags.append("StringFormatBypassGDI "); |
79 | | |
80 | | // There will be 1 extra space in the end. It could be truncated, but |
81 | | // as it is for SAL_INFO() only, it would not be important |
82 | 0 | return sFlags.makeStringAndClear(); |
83 | 0 | } |
84 | | |
85 | | static OUString StringAlignmentString(sal_uInt32 nAlignment) |
86 | 0 | { |
87 | 0 | switch(nAlignment) |
88 | 0 | { |
89 | 0 | case StringAlignment::StringAlignmentNear: |
90 | 0 | return u"StringAlignmentNear"_ustr; |
91 | 0 | case StringAlignment::StringAlignmentCenter: |
92 | 0 | return u"StringAlignmentCenter"_ustr; |
93 | 0 | case StringAlignment::StringAlignmentFar: |
94 | 0 | return u"StringAlignmentFar"_ustr; |
95 | 0 | default: |
96 | 0 | assert(false && nAlignment && "invalid string alignment value"); |
97 | 0 | return u"INVALID"_ustr; |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | static OUString DigitSubstitutionString(sal_uInt32 nSubst) |
102 | 0 | { |
103 | 0 | switch(nSubst) |
104 | 0 | { |
105 | 0 | case StringDigitSubstitution::StringDigitSubstitutionUser: |
106 | 0 | return u"StringDigitSubstitutionUser"_ustr; |
107 | 0 | case StringDigitSubstitution::StringDigitSubstitutionNone: |
108 | 0 | return u"StringDigitSubstitutionNone"_ustr; |
109 | 0 | case StringDigitSubstitution::StringDigitSubstitutionNational: |
110 | 0 | return u"StringDigitSubstitutionNational"_ustr; |
111 | 0 | case StringDigitSubstitution::StringDigitSubstitutionTraditional: |
112 | 0 | return u"StringDigitSubstitutionTraditional"_ustr; |
113 | 0 | default: |
114 | 0 | assert(false && nSubst && "invalid string digit substitution value"); |
115 | 0 | return u"INVALID"_ustr; |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | static OUString HotkeyPrefixString(sal_uInt32 nHotkey) |
120 | 0 | { |
121 | 0 | switch(nHotkey) |
122 | 0 | { |
123 | 0 | case HotkeyPrefix::HotkeyPrefixNone: |
124 | 0 | return u"HotkeyPrefixNone"_ustr; |
125 | 0 | case HotkeyPrefix::HotkeyPrefixShow: |
126 | 0 | return u"HotkeyPrefixShow"_ustr; |
127 | 0 | case HotkeyPrefix::HotkeyPrefixHide: |
128 | 0 | return u"HotkeyPrefixHide"_ustr; |
129 | 0 | default: |
130 | 0 | assert(false && nHotkey && "invalid hotkey prefix value"); |
131 | 0 | return u"INVALID"_ustr; |
132 | 0 | } |
133 | 0 | } |
134 | | |
135 | | static OUString StringTrimmingString(sal_uInt32 nTrimming) |
136 | 0 | { |
137 | 0 | switch(nTrimming) |
138 | 0 | { |
139 | 0 | case StringTrimming::StringTrimmingNone: |
140 | 0 | return u"StringTrimmingNone"_ustr; |
141 | 0 | case StringTrimming::StringTrimmingCharacter: |
142 | 0 | return u"StringTrimmingCharacter"_ustr; |
143 | 0 | case StringTrimming::StringTrimmingWord: |
144 | 0 | return u"StringTrimmingWord"_ustr; |
145 | 0 | case StringTrimming::StringTrimmingEllipsisCharacter: |
146 | 0 | return u"StringTrimmingEllipsisCharacter"_ustr; |
147 | 0 | case StringTrimming::StringTrimmingEllipsisWord: |
148 | 0 | return u"StringTrimmingEllipsisWord"_ustr; |
149 | 0 | case StringTrimming::StringTrimmingEllipsisPath: |
150 | 0 | return u"StringTrimmingEllipsisPath"_ustr; |
151 | 0 | default: |
152 | 0 | assert(false && nTrimming && "invalid trim value"); |
153 | 0 | return u"INVALID"_ustr; |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | void EMFPStringFormat::Read(SvMemoryStream &s) |
158 | 0 | { |
159 | 0 | s.ReadUInt32(header).ReadUInt32(stringFormatFlags).ReadUInt32(language); |
160 | 0 | s.ReadUInt32(stringAlignment).ReadUInt32(lineAlign).ReadUInt32(digitSubstitution).ReadUInt32(digitLanguage); |
161 | 0 | s.ReadFloat(firstTabOffset).ReadInt32(hotkeyPrefix).ReadFloat(leadingMargin).ReadFloat(trailingMargin).ReadFloat(tracking); |
162 | 0 | s.ReadInt32(trimming).ReadInt32(tabStopCount).ReadInt32(rangeCount); |
163 | | // keep only the last 16 bits of language |
164 | 0 | language >>= 16; |
165 | 0 | digitLanguage >>= 16; |
166 | 0 | SAL_WARN_IF((header >> 12) != 0xdbc01, "drawinglayer.emf", "Invalid header - not 0xdbc01"); |
167 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\tString format"); |
168 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tHeader: 0x" << std::hex << (header >> 12)); |
169 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tVersion: 0x" << (header & 0x1fff) << std::dec); |
170 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tStringFormatFlags: " << StringFormatFlags(stringFormatFlags)); |
171 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tLanguage: sublangid: 0x" << std::hex << (language >> 10) << ", primarylangid: 0x" << (language & 0xF800)); |
172 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tLineAlign: " << StringAlignmentString(lineAlign)); |
173 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tDigitSubstitution: " << DigitSubstitutionString(digitSubstitution)); |
174 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tDigitLanguage: sublangid: 0x" << std::hex << (digitLanguage >> 10) << ", primarylangid: 0x" << (digitLanguage & 0xF800)); |
175 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tFirstTabOffset: " << firstTabOffset); |
176 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tHotkeyPrefix: " << HotkeyPrefixString(hotkeyPrefix)); |
177 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tLeadingMargin: " << leadingMargin); |
178 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tTrailingMargin: " << trailingMargin); |
179 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tTracking: " << tracking); |
180 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tTrimming: " << StringTrimmingString(trimming)); |
181 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tTabStopCount: " << tabStopCount); |
182 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\t\tRangeCount: " << rangeCount); |
183 | | |
184 | 0 | SAL_WARN_IF(digitSubstitution != StringDigitSubstitution::StringDigitSubstitutionNone, |
185 | 0 | "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:digitSubstitution"); |
186 | 0 | SAL_WARN_IF(firstTabOffset != 0.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:firstTabOffset"); |
187 | 0 | SAL_WARN_IF(hotkeyPrefix != HotkeyPrefix::HotkeyPrefixNone, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:hotkeyPrefix"); |
188 | 0 | SAL_WARN_IF(tracking != 1.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:tracking"); |
189 | 0 | SAL_WARN_IF(trimming != StringTrimming::StringTrimmingNone, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:trimming"); |
190 | 0 | SAL_WARN_IF(tabStopCount, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:tabStopCount"); |
191 | 0 | SAL_WARN_IF(rangeCount != 0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:StringFormatData"); |
192 | 0 | } |
193 | | } |
194 | | |
195 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |