1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_STARMATH_INC_UTILITY_HXX
20 #define INCLUDED_STARMATH_INC_UTILITY_HXX
22 #include <sal/config.h>
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>
33 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.
39 SAL_WARN_IF( nNumPts
< 0, "starmath", "Ooops..." );
40 // broken into multiple and fraction of 'nNumPts' to reduce chance
42 // (7227 / 2) is added in order to round to the nearest integer
43 return 35 * nNumPts
+ (nNumPts
* 1055L + (7227 / 2)) / 7227L;
47 inline Fraction
Sm100th_mmToPts(long nNum100th_mm
)
48 // returns the length (in points) that corresponds to the length
49 // 'nNum100th_mm' (in 100th of mm).
51 SAL_WARN_IF( nNum100th_mm
< 0, "starmath", "Ooops..." );
52 Fraction
aTmp (7227L, 254000L);
53 return aTmp
*= Fraction(nNum100th_mm
);
57 inline long SmRoundFraction(const Fraction
&rFrac
)
59 SAL_WARN_IF( rFrac
<= Fraction(), "starmath", "Ooops..." );
60 return (rFrac
.GetNumerator() + rFrac
.GetDenominator() / 2) / rFrac
.GetDenominator();
65 SmViewShell
* SmGetActiveView();
71 bool IsItalic( const vcl::Font
&rFont
);
72 bool IsBold( const vcl::Font
&rFont
);
74 class SmFace
: public vcl::Font
82 Font(), nBorderWidth(-1) { Impl_Init(); }
83 SmFace(const Font
& rFont
) :
84 Font(rFont
), nBorderWidth(-1) { Impl_Init(); }
85 SmFace(const OUString
& rName
, const Size
& rSize
) :
86 Font(rName
, rSize
), nBorderWidth(-1) { Impl_Init(); }
88 SmFace(const SmFace
&rFace
) :
89 Font(rFace
), nBorderWidth(-1) { Impl_Init(); }
91 // overloaded version in order to supply a min value
92 // for font size (height). (Also used in ctor's to do so.)
93 void SetSize(const Size
& rSize
);
95 void SetBorderWidth(long nWidth
) { nBorderWidth
= nWidth
; }
96 long GetBorderWidth() const;
97 long GetDefaultBorderWidth() const { return GetFontSize().Height() / 20 ; }
98 void FreezeBorderWidth() { nBorderWidth
= GetDefaultBorderWidth(); }
100 SmFace
& operator = (const SmFace
&rFace
);
103 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
);
114 sal_uInt16 nMaxItems
;
115 std::deque
<vcl::Font
> aFontVec
;
118 explicit SmFontPickList(sal_uInt16 nMax
= 5) : nMaxItems(nMax
) {}
119 virtual ~SmFontPickList() { Clear(); }
121 virtual void Insert(const vcl::Font
&rFont
);
124 vcl::Font
Get(sal_uInt16 nPos
= 0) const;
126 SmFontPickList
& operator = (const SmFontPickList
& rList
);
128 void ReadFrom(const SmFontDialog
& rDialog
);
129 void WriteTo(SmFontDialog
& rDialog
) const;
136 class SmFontPickListBox final
: public SmFontPickList
, public ListBox
138 DECL_LINK(SelectHdl
, ListBox
&, void);
141 SmFontPickListBox(vcl::Window
* pParent
, WinBits nBits
);
143 SmFontPickListBox
& operator = (const SmFontPickList
& rList
);
145 virtual void Insert(const vcl::Font
&rFont
) override
;
146 using Window::Update
;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */