Line data Source code
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 : #ifndef INCLUDED_STARMATH_INC_UTILITY_HXX
20 : #define INCLUDED_STARMATH_INC_UTILITY_HXX
21 :
22 : #include <sal/config.h>
23 :
24 : #include <sal/log.hxx>
25 : #include <vcl/font.hxx>
26 : #include <vcl/fixed.hxx>
27 : #include <vcl/combobox.hxx>
28 : #include <vcl/lstbox.hxx>
29 : #include <tools/fract.hxx>
30 : #include <deque>
31 :
32 :
33 647 : inline long SmPtsTo100th_mm(long nNumPts)
34 : // returns the length (in 100th of mm) that corresponds to the length
35 : // 'nNumPts' (in units points).
36 : // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
37 : // result is being rounded to the nearest integer.
38 : {
39 : SAL_WARN_IF( nNumPts < 0, "starmath", "Ooops..." );
40 : // broken into multiple and fraction of 'nNumPts' to reduce chance
41 : // of overflow
42 : // (7227 / 2) is added in order to round to the nearest integer
43 647 : return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
44 : }
45 :
46 :
47 : inline long SmPtsTo100th_mm(const Fraction &rNumPts)
48 : // as above but with argument 'rNumPts' as 'Fraction'
49 : {
50 : Fraction aTmp (254000L, 7227L);
51 : return aTmp *= rNumPts;
52 : }
53 :
54 :
55 0 : inline Fraction Sm100th_mmToPts(long nNum100th_mm)
56 : // returns the length (in points) that corresponds to the length
57 : // 'nNum100th_mm' (in 100th of mm).
58 : {
59 : SAL_WARN_IF( nNum100th_mm < 0, "starmath", "Ooops..." );
60 0 : Fraction aTmp (7227L, 254000L);
61 0 : return aTmp *= Fraction(nNum100th_mm);
62 : }
63 :
64 :
65 0 : inline long SmRoundFraction(const Fraction &rFrac)
66 : {
67 : SAL_WARN_IF( rFrac <= Fraction(), "starmath", "Ooops..." );
68 0 : return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
69 : }
70 :
71 :
72 : class SmViewShell;
73 : SmViewShell * SmGetActiveView();
74 :
75 :
76 :
77 :
78 : // SmFace
79 :
80 :
81 : bool IsItalic( const vcl::Font &rFont );
82 : bool IsBold( const vcl::Font &rFont );
83 :
84 24723 : class SmFace : public vcl::Font
85 : {
86 : long nBorderWidth;
87 :
88 : void Impl_Init();
89 :
90 : public:
91 23208 : SmFace() :
92 23208 : Font(), nBorderWidth(-1) { Impl_Init(); }
93 1470 : SmFace(const Font& rFont) :
94 1470 : Font(rFont), nBorderWidth(-1) { Impl_Init(); }
95 1491 : SmFace(const OUString& rName, const Size& rSize) :
96 1491 : Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
97 : SmFace( FontFamily eFamily, const Size& rSize) :
98 : Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
99 :
100 7 : SmFace(const SmFace &rFace) :
101 7 : Font(rFace), nBorderWidth(-1) { Impl_Init(); }
102 :
103 : // overloaded version in order to supply a min value
104 : // for font size (height). (Also used in ctor's to do so.)
105 : void SetSize(const Size& rSize);
106 :
107 7 : void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
108 : long GetBorderWidth() const;
109 8457 : long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
110 1223 : void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
111 :
112 : SmFace & operator = (const SmFace &rFace);
113 : };
114 :
115 : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
116 :
117 :
118 :
119 :
120 : // SmFontPickList
121 :
122 :
123 : class SmFontDialog;
124 :
125 : class SmFontPickList
126 : {
127 : protected:
128 : sal_uInt16 nMaxItems;
129 : std::deque<vcl::Font> aFontVec;
130 :
131 : static bool CompareItem(const vcl::Font & rFirstFont, const vcl::Font & rSecondFont);
132 : static OUString GetStringItem(const vcl::Font &rItem);
133 :
134 : public:
135 98 : SmFontPickList(sal_uInt16 nMax = 5) : nMaxItems(nMax) {}
136 14 : virtual ~SmFontPickList() { Clear(); }
137 :
138 : virtual void Insert(const vcl::Font &rFont);
139 : virtual void Update(const vcl::Font &rFont, const vcl::Font &rNewFont);
140 : virtual void Remove(const vcl::Font &rFont);
141 :
142 : void Clear();
143 : vcl::Font Get(sal_uInt16 nPos = 0) const;
144 :
145 : SmFontPickList& operator = (const SmFontPickList& rList);
146 : vcl::Font operator [] (sal_uInt16 nPos) const;
147 :
148 : void ReadFrom(const SmFontDialog& rDialog);
149 : void WriteTo(SmFontDialog& rDialog) const;
150 : };
151 :
152 :
153 :
154 : // SmFontPickListBox
155 :
156 :
157 0 : class SmFontPickListBox : public SmFontPickList, public ListBox
158 : {
159 : protected:
160 : DECL_LINK(SelectHdl, ListBox *);
161 :
162 : public:
163 : SmFontPickListBox(vcl::Window* pParent, WinBits nBits);
164 :
165 : SmFontPickListBox& operator = (const SmFontPickList& rList);
166 :
167 : virtual void Insert(const vcl::Font &rFont) SAL_OVERRIDE;
168 : using Window::Update;
169 : virtual void Update(const vcl::Font &rFont, const vcl::Font &rNewFont) SAL_OVERRIDE;
170 : virtual void Remove(const vcl::Font &rFont) SAL_OVERRIDE;
171 : };
172 :
173 : #endif
174 :
175 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|