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 .
22 #include <sal/config.h>
24 #include <sal/log.hxx>
25 #include <vcl/font.hxx>
26 #include <vcl/weld.hxx>
27 #include <tools/fract.hxx>
30 inline tools::Long
SmPtsTo100th_mm(tools::Long nNumPts
)
31 // returns the length (in 100th of mm) that corresponds to the length
32 // 'nNumPts' (in units points).
33 // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
34 // result is being rounded to the nearest integer.
36 SAL_WARN_IF( nNumPts
< 0, "starmath", "Ooops..." );
37 // broken into multiple and fraction of 'nNumPts' to reduce chance
39 // (7227 / 2) is added in order to round to the nearest integer
40 return 35 * nNumPts
+ (nNumPts
* 1055L + (7227 / 2)) / 7227L;
44 inline Fraction
Sm100th_mmToPts(tools::Long nNum100th_mm
)
45 // returns the length (in points) that corresponds to the length
46 // 'nNum100th_mm' (in 100th of mm).
48 SAL_WARN_IF( nNum100th_mm
< 0, "starmath", "Ooops..." );
49 return Fraction(7227L, 254000L) * Fraction(nNum100th_mm
);
53 inline tools::Long
SmRoundFraction(const Fraction
&rFrac
)
55 SAL_WARN_IF( rFrac
<= Fraction(), "starmath", "Ooops..." );
56 return (rFrac
.GetNumerator() + rFrac
.GetDenominator() / 2) / rFrac
.GetDenominator();
61 SmViewShell
* SmGetActiveView();
67 bool IsItalic( const vcl::Font
&rFont
);
68 bool IsBold( const vcl::Font
&rFont
);
70 class SmFace final
: public vcl::Font
72 tools::Long nBorderWidth
;
78 Font(), nBorderWidth(-1) { Impl_Init(); }
79 SmFace(const Font
& rFont
) :
80 Font(rFont
), nBorderWidth(-1) { Impl_Init(); }
81 SmFace(const OUString
& rName
, const Size
& rSize
) :
82 Font(rName
, rSize
), nBorderWidth(-1) { Impl_Init(); }
84 SmFace(const SmFace
&rFace
) :
85 Font(rFace
), nBorderWidth(-1) { Impl_Init(); }
87 // overloaded version in order to supply a min value
88 // for font size (height). (Also used in ctor's to do so.)
89 void SetSize(const Size
& rSize
);
91 void SetBorderWidth(tools::Long nWidth
) { nBorderWidth
= nWidth
; }
92 tools::Long
GetBorderWidth() const;
93 tools::Long
GetDefaultBorderWidth() const { return GetFontSize().Height() / 20 ; }
94 void FreezeBorderWidth() { nBorderWidth
= GetDefaultBorderWidth(); }
96 SmFace
& operator = (const SmFace
&rFace
);
99 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
);
110 sal_uInt16 nMaxItems
;
111 std::deque
<vcl::Font
> aFontVec
;
114 explicit SmFontPickList(sal_uInt16 nMax
= 5) : nMaxItems(nMax
) {}
115 virtual ~SmFontPickList() { Clear(); }
117 virtual void Insert(const vcl::Font
&rFont
);
120 vcl::Font
Get(sal_uInt16 nPos
= 0) const;
122 SmFontPickList
& operator = (const SmFontPickList
& rList
);
124 void ReadFrom(const SmFontDialog
& rDialog
);
125 void WriteTo(SmFontDialog
& rDialog
) const;
132 class SmFontPickListBox final
: public SmFontPickList
135 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
137 DECL_LINK(SelectHdl
, weld::ComboBox
&, void);
140 SmFontPickListBox(std::unique_ptr
<weld::ComboBox
> pWidget
);
141 SmFontPickListBox
& operator = (const SmFontPickList
& rList
);
142 virtual void Insert(const vcl::Font
&rFont
) override
;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */