summaryrefslogtreecommitdiff
path: root/starmath/source/format.cxx
blob: f79388822b41e53a60d6aa0d59e663ccf6aabb4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*************************************************************************
 *
 *  $RCSfile: format.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: tl $ $Date: 2000-11-02 15:07:16 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif

#ifndef FORMAT_HXX
#include "format.hxx"
#endif

SmFormat::SmFormat()
:   aBaseSize(0, SmPtsTo100th_mm(12))
{
    nVersion    = SM_FMT_VERSION_NOW;

    eHorAlign   = AlignCenter;
    bIsTextmode = bScaleNormalBrackets = FALSE;

    vSize[SIZ_TEXT]     = 100;
    vSize[SIZ_INDEX]    = 60;
    vSize[SIZ_FUNCTION] =
    vSize[SIZ_OPERATOR] = 100;
    vSize[SIZ_LIMITS]   = 60;

    vDist[DIS_HORIZONTAL]           = 10;
    vDist[DIS_VERTICAL]             = 5;
    vDist[DIS_ROOT]                 = 0;
    vDist[DIS_SUPERSCRIPT]          =
    vDist[DIS_SUBSCRIPT]            = 20;
    vDist[DIS_NUMERATOR]            =
    vDist[DIS_DENOMINATOR]          = 0;
    vDist[DIS_FRACTION]             = 10;
    vDist[DIS_STROKEWIDTH]          = 5;
    vDist[DIS_UPPERLIMIT]           =
    vDist[DIS_LOWERLIMIT]           = 0;
    vDist[DIS_BRACKETSIZE]          =
    vDist[DIS_BRACKETSPACE]         = 5;
    vDist[DIS_MATRIXROW]            = 3;
    vDist[DIS_MATRIXCOL]            = 30;
    vDist[DIS_ORNAMENTSIZE]         =
    vDist[DIS_ORNAMENTSPACE]        = 0;
    vDist[DIS_OPERATORSIZE]         = 50;
    vDist[DIS_OPERATORSPACE]        = 20;
    vDist[DIS_LEFTSPACE]            =
    vDist[DIS_RIGHTSPACE]           = 100;
    vDist[DIS_TOPSPACE]             =
    vDist[DIS_BOTTOMSPACE]          =
    vDist[DIS_NORMALBRACKETSIZE]    = 0;

    vFont[FNT_VARIABLE] =
    vFont[FNT_FUNCTION] =
    vFont[FNT_NUMBER]   =
    vFont[FNT_TEXT]     =
    vFont[FNT_SERIF]    = SmFace(C2S(FNTNAME_TIMES), aBaseSize);
    vFont[FNT_SANS]     = SmFace(C2S(FNTNAME_HELV),  aBaseSize);
    vFont[FNT_FIXED]    = SmFace(C2S(FNTNAME_COUR),  aBaseSize);
    vFont[FNT_MATH]     = SmFace(C2S(FNTNAME_MATH),  aBaseSize);

    vFont[FNT_VARIABLE].SetItalic(ITALIC_NORMAL);
    vFont[FNT_FUNCTION].SetItalic(ITALIC_NONE);
    vFont[FNT_TEXT].SetItalic(ITALIC_NONE);

    for ( USHORT i = FNT_BEGIN;  i <= FNT_END;  i++ )
    {
        vFont[i].SetTransparent(TRUE);
        vFont[i].SetAlign(ALIGN_BASELINE);
    }
}


SmFormat & SmFormat::operator = (const SmFormat &rFormat)
{
    SetBaseSize(rFormat.GetBaseSize());
    SetVersion (rFormat.GetVersion());
    SetHorAlign(rFormat.GetHorAlign());
    SetTextmode(rFormat.IsTextmode());
    SetScaleNormalBrackets(rFormat.IsScaleNormalBrackets());

    USHORT  i;
    for (i = FNT_BEGIN;  i <= FNT_END;  i++)
        SetFont(i, rFormat.GetFont(i));
    for (i = SIZ_BEGIN;  i <= SIZ_END;  i++)
        SetRelSize(i, rFormat.GetRelSize(i));
    for (i = DIS_BEGIN;  i <= DIS_END;  i++)
        SetDistance(i, rFormat.GetDistance(i));

    return *this;
}


SvStream & operator << (SvStream &rStream, const SmFormat &rFormat)
{
    //Da hier keinerlei Kompatibilit„t vorgesehen ist muessen wir leider
    //heftig tricksen. Gluecklicherweise sind offenbar einige Informationen
    //ueberfluessig geworden. In diese quetschen wir jetzt vier neue
    //Einstellungen fuer die Rander.
    //Bei Gelegenheit wird hier ein Im- Und Export gebraucht. Dann muessen
    //die Stream-Operatoren dieser Klassen dringend mit Versionsverwaltung
    //versehen werden!

    UINT16  n;

    // convert the heigth (in 100th of mm) to Pt and round the result to the
    // nearest integer
    n = (UINT16) SmRoundFraction(Sm100th_mmToPts(rFormat.aBaseSize.Height()));
    DBG_ASSERT((n & 0xFF00) == 0, "Sm : higher Byte nicht leer");

    // to be compatible with the old format (size and order) we put the info
    // about textmode in the higher byte (height is already restricted to a
    // maximum of 127!)
    n |=   (rFormat.bIsTextmode != 0)          << 8
         | (rFormat.bScaleNormalBrackets != 0) << 9;
    rStream << n;

    rStream << rFormat.vDist[DIS_LEFTSPACE];    //Wir nutzen den Platz
    rStream << rFormat.vDist[DIS_RIGHTSPACE];   //Wir nutzen den Platz

    for ( n = SIZ_BEGIN; n <= SIZ_END; ++n )
        rStream << rFormat.vSize[n];

    rStream << rFormat.vDist[DIS_TOPSPACE];     //Wir nutzen den Platz

    for ( n = 0; n <= FNT_FIXED; ++n )
        rStream << rFormat.vFont[n];

    // Den zweiten Wert noch im HigherByte unterbringen
    USHORT uTmp =   rFormat.vDist[DIS_BRACKETSIZE]
                  | rFormat.vDist[DIS_NORMALBRACKETSIZE] << 8;
    // und dann dieses rausstreamen
    for ( n = 0; n <= DIS_OPERATORSPACE; ++n )
        rStream << (USHORT)(n != DIS_BRACKETSIZE ? rFormat.vDist[(USHORT) n] : uTmp);

    // higher byte is version number, lower byte is horizontal alignment
    n = rFormat.eHorAlign | SM_FMT_VERSION_NOW << 8;
    rStream << n;

    rStream << rFormat.vDist[DIS_BOTTOMSPACE];  //Wir nutzen den Platz

    return rStream;
}


SvStream & operator >> (SvStream &rStream, SmFormat &rFormat)
{
    UINT16  n;

    rStream >> n;
    long nBaseHeight    = n & 0x00FF;
    rFormat.bIsTextmode          = ((n >> 8) & 0x01) != 0;
    rFormat.bScaleNormalBrackets = ((n >> 9) & 0x01) != 0;
    rFormat.aBaseSize   = Size(0, SmPtsTo100th_mm(nBaseHeight));

    rStream >> rFormat.vDist[DIS_LEFTSPACE];    //Wir nutzen den Platz
    rStream >> rFormat.vDist[DIS_RIGHTSPACE];   //Wir nutzen den Platz

    for ( n = SIZ_BEGIN; n <= SIZ_END; ++n )
        rStream >> rFormat.vSize[n];

    rStream >> rFormat.vDist[DIS_TOPSPACE];     //Wir nutzen den Platz

    for ( n = 0; n <= FNT_FIXED; ++n )
        rStream >> rFormat.vFont[n];

    for ( n = 0; n <= DIS_OPERATORSPACE; ++n )
        rStream >> rFormat.vDist[n];
    // den zweiten Wert aus dem HigherByte holen
    rFormat.vDist[DIS_NORMALBRACKETSIZE] = rFormat.vDist[DIS_BRACKETSIZE] >> 8;
    // und dieses dann ausblenden
    rFormat.vDist[DIS_BRACKETSIZE] &= 0x00FF;

    // higher byte is version number, lower byte is horizontal alignment
    rStream >> n;
    rFormat.nVersion  = n >> 8;
    rFormat.eHorAlign = (SmHorAlign) (n & 0x00FF);

    rStream >> rFormat.vDist[DIS_BOTTOMSPACE];  //Wir nutzen den Platz

    const Size aTmp( rFormat.GetBaseSize() );
    for ( USHORT i = 0; i <= FNT_FIXED; ++i )
    {
        rFormat.vFont[i].SetSize(aTmp);
        rFormat.vFont[i].SetTransparent(TRUE);
        rFormat.vFont[i].SetAlign(ALIGN_BASELINE);
    }
    rFormat.vFont[FNT_MATH].SetSize(aTmp);

    // Für Version 4.0 (und älter) sollen auch die normalen Klammern skalierbar
    // sein und wachsen (so wie es der Fall war), in der 5.0 Version jedoch nicht.
    // In späteren Versionen (>= 5.1) ist das Verhalten nun durch den Anwender
    // festzulegen (bleibt also wie aus dem Stream gelesen).
    if (rFormat.nVersion < SM_FMT_VERSION_51)
    {
        BOOL    bIs50Stream = rStream.GetVersion() == SOFFICE_FILEFORMAT_50;
        BOOL    bVal        = bIs50Stream ? FALSE : TRUE;
        USHORT  nExcHeight  = bIs50Stream ? 0 : rFormat.vDist[DIS_BRACKETSIZE];

        rFormat.SetScaleNormalBrackets(bVal);
        rFormat.SetDistance(DIS_NORMALBRACKETSIZE, nExcHeight);
    }

    return rStream;
}

void SmFormat::ReadSM20Format(SvStream &rStream)
{
    UINT16  n;
    USHORT  i;

    rStream >> n;
    SetBaseSize( Size(0, SmPtsTo100th_mm(n)) );

    rStream >> n >> n;

    for (i = SIZ_BEGIN;  i <= SIZ_LIMITS;  i++)
    {   rStream >> n;
        SetRelSize(i, n);
    }

    rStream >> n;

    for (i = FNT_BEGIN;  i <= FNT_FIXED;  i++)
        ReadSM20Font(rStream, Font(i));

    for (i = DIS_BEGIN;  i <= DIS_OPERATORSPACE;  i++)
    {   rStream >> n;
        SetDistance(i, n);
    }

    rStream >> n;
    SetHorAlign((SmHorAlign) n);
    rStream >> n;

    const Size  aTmp (GetBaseSize());
    for (i = FNT_BEGIN;  i <= FNT_FIXED;  i++)
    {
        Font(i).SetSize(aTmp);
        Font(i).SetTransparent(TRUE);
        Font(i).SetAlign(ALIGN_BASELINE);
    }
    Font(FNT_MATH).SetSize(aTmp);
}


void SmFormat::From300To304a()
{
    long nBaseSize = SmRoundFraction(Sm100th_mmToPts(aBaseSize.Height()))
                     * 2540l / 72l;
    for (USHORT i = DIS_BEGIN;  i < DIS_OPERATORSPACE;  i++)
        SetDistance(i, USHORT(GetDistance(i) * 254000L / 72L / nBaseSize));
}