PCL
Font.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Font.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Font_h
53 #define __PCL_Font_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/Rectangle.h>
62 #include <pcl/StringList.h>
63 #include <pcl/UIObject.h>
64 
65 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
66 
67 namespace pcl
68 {
69 
70 // ----------------------------------------------------------------------------
71 
93 namespace FontFamily
94 {
95  enum value_type
96  {
97  Default, // default font
98  SansSerif, // sans serif font: Helvetica, Swiss, Arial
99  Helvetica = SansSerif,
100  Swiss = SansSerif,
101  Serif, // serif font: Times, Garamond
102  Times = Serif,
103  Script, // handwriting font: Script, Comic
104  Monospace, // fixed-pitch font: Courier, Vera Sans Mono
105  TypeWriter = Monospace,
106  Courier = Monospace,
107  Teletype = Monospace,
108  Decorative, // decorative font: OldEnglish,
109  OldEnglish = Decorative,
110  Symbol // math, greek, etc.: Symbol
111  };
112 
113  String PCL_FUNC FamilyToFace( value_type family );
114 }
115 
116 // ----------------------------------------------------------------------------
117 
139 namespace FontWeight
140 {
141  enum value_type
142  {
143  Thin = 100,
144  ExtraLight = 200,
145  UltraLight = ExtraLight,
146  Light = 300,
147  Normal = 400,
148  Regular = Normal,
149  Medium = 500,
150  SemiBold = 600,
151  DemiBold = SemiBold,
152  Bold = 700,
153  ExtraBold = 800,
154  UltraBold = ExtraBold,
155  Heavy = 850,
156  Black = 900
157  };
158 }
159 
160 // ----------------------------------------------------------------------------
161 
178 namespace FontStretch
179 {
180  enum value_type
181  {
182  UltraCondensed = 50,
183  ExtraCondensed = 62,
184  Condensed = 75,
185  SemiCondensed = 87,
186  Unstretched = 100,
187  SemiExpanded = 112,
188  Expanded = 125,
189  ExtraExpanded = 150,
190  UltraExpanded = 200
191  };
192 }
193 
194 // ----------------------------------------------------------------------------
195 
196 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
197 
198 // ----------------------------------------------------------------------------
199 
206 class PCL_CLASS Font : public UIObject
207 {
208 public:
209 
213  using family = FontFamily::value_type;
214 
218  using std_weight = FontWeight::value_type;
219 
223  using std_stretch = FontStretch::value_type;
224 
231  Font( family f = FontFamily::Default, double size = 12.0 );
232 
239  Font( const String& face, double size = 12.0 );
240 
245  Font( const Font& f ) : UIObject( f )
246  {
247  }
248 
252  Font( Font&& x ) : UIObject( std::move( x ) )
253  {
254  }
255 
261  ~Font() override
262  {
263  }
264 
272  Font& operator =( const Font& f )
273  {
274  SetHandle( f.handle );
275  return *this;
276  }
277 
281  Font& operator =( Font&& x )
282  {
283  Transfer( x );
284  return *this;
285  }
286 
291  static Font& Null();
292 
295  String Face() const;
296 
299  void SetFace( const String& );
300 
303  bool IsExactMatch() const;
304 
308  {
309  return AvailableFontWritingSystems( Face() );
310  }
311 
315  {
316  return AvailableFontStyles( Face() );
317  }
318 
321  bool IsScalable( const String& style = String() ) const
322  {
323  return IsScalableFont( Face(), style );
324  }
325 
328  Array<double> OptimalPointSizes( const String& style = String() ) const
329  {
330  return OptimalFontPointSizes( Face(), style );
331  }
332 
335  int PixelSize() const;
336 
339  void SetPixelSize ( int );
340 
343  double PointSize() const;
344 
347  void SetPointSize( double );
348 
351  bool IsFixedPitch() const;
352 
355  bool IsFixedPitch( const String& style ) const
356  {
357  return IsFixedPitchFont( Face(), style );
358  }
359 
362  void SetFixedPitch( bool = true );
363 
366  bool IsKerningEnabled() const;
367 
370  void EnableKerning( bool = true );
371 
374  void DisableKerning( bool = true );
375 
378  int StretchFactor() const;
379 
382  void SetStretchFactor( int );
383 
386  int Weight() const;
387 
390  int Weight( const String& style ) const
391  {
392  return FontWeight( Face(), style );
393  }
394 
397  void SetWeight( int );
398 
401  bool IsBold() const
402  {
403  return Weight() >= FontWeight::Bold;
404  }
405 
408  void SetBold( bool b = true )
409  {
410  SetWeight( b ? FontWeight::Bold : FontWeight::Normal );
411  }
412 
415  bool IsItalic() const;
416 
419  bool IsItalic( const String& style ) const
420  {
421  return IsItalicFont( Face(), style );
422  }
423 
426  void SetItalic( bool = true );
427 
430  bool IsUnderline() const;
431 
434  void SetUnderline( bool = true );
435 
438  bool IsOverline() const;
439 
442  void SetOverline( bool = true );
443 
446  bool IsStrikeOut() const;
447 
450  void SetStrikeOut( bool = true );
451 
454  int Ascent() const;
455 
458  int Descent() const;
459 
462  int Height() const;
463 
466  int LineSpacing() const;
467 
470  bool IsCharDefined( int ) const;
471 
474  int MaxWidth() const;
475 
478  int Width( const String& ) const;
479 
482  int Width( int ch ) const;
483 
486  Rect BoundingRect( const String& ) const;
487 
490  Rect TightBoundingRect( const String& ) const;
491 
494  static StringList AvailableFonts( const String& writingSystem = String() );
495 
499 
502  static StringList AvailableFontStyles( const String& font );
503 
506  static Array<double> OptimalFontPointSizes( const String& font, const String& style = String() );
507 
510  static bool IsScalableFont( const String& font, const String& style = String() );
511 
514  static bool IsFixedPitchFont( const String& font, const String& style = String() );
515 
518  static bool IsItalicFont( const String& font, const String& style = String() );
519 
522  static int FontWeight( const String& font, const String& style = String() );
523 
524 private:
525 
526  Font( void* h ) : UIObject( h )
527  {
528  }
529 
530  void* CloneHandle() const override;
531 
532  friend class InternalFontEnumerator;
533  friend class GraphicsContextBase;
534  friend class Control;
535  friend class TreeBox;
536 };
537 
538 // ----------------------------------------------------------------------------
539 
540 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
541 
542 } // pcl
543 
544 #endif // __PCL_Font_h
545 
546 // ----------------------------------------------------------------------------
547 // EOF pcl/Font.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
Client-side interface to a PixInsight Font object.
Definition: Font.h:207
int Descent() const
bool IsUnderline() const
Rect BoundingRect(const String &) const
static Font & Null()
int Weight() const
bool IsItalic(const String &style) const
Definition: Font.h:419
bool IsBold() const
Definition: Font.h:401
void SetItalic(bool=true)
void EnableKerning(bool=true)
int PixelSize() const
static int FontWeight(const String &font, const String &style=String())
static StringList AvailableFonts(const String &writingSystem=String())
void SetStretchFactor(int)
bool IsExactMatch() const
Font(Font &&x)
Definition: Font.h:252
Font(family f=FontFamily::Default, double size=12.0)
Rect TightBoundingRect(const String &) const
static bool IsItalicFont(const String &font, const String &style=String())
bool IsCharDefined(int) const
static Array< double > OptimalFontPointSizes(const String &font, const String &style=String())
static StringList AvailableFontStyles(const String &font)
double PointSize() const
void DisableKerning(bool=true)
void SetPixelSize(int)
int Width(const String &) const
int LineSpacing() const
StringList AvailableStyles() const
Definition: Font.h:314
void SetFixedPitch(bool=true)
int Weight(const String &style) const
Definition: Font.h:390
bool IsItalic() const
void SetWeight(int)
void SetPointSize(double)
void SetBold(bool b=true)
Definition: Font.h:408
static bool IsFixedPitchFont(const String &font, const String &style=String())
Array< double > OptimalPointSizes(const String &style=String()) const
Definition: Font.h:328
void SetFace(const String &)
int MaxWidth() const
static StringList AvailableFontWritingSystems(const String &font)
Font(const Font &f)
Definition: Font.h:245
int Ascent() const
bool IsScalable(const String &style=String()) const
Definition: Font.h:321
bool IsFixedPitch(const String &style) const
Definition: Font.h:355
int Width(int ch) const
bool IsStrikeOut() const
void SetUnderline(bool=true)
static bool IsScalableFont(const String &font, const String &style=String())
void SetStrikeOut(bool=true)
int Height() const
void SetOverline(bool=true)
bool IsKerningEnabled() const
Font(const String &face, double size=12.0)
bool IsFixedPitch() const
StringList AvailableWritingSystems() const
Definition: Font.h:307
bool IsOverline() const
int StretchFactor() const
~Font() override
Definition: Font.h:261
String Face() const
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
Base class of client-side interface classes to PixInsight graphics contexts
Definition: Graphics.h:208
Unicode (UTF-16) string.
Definition: String.h:8113
Client-side interface to a PixInsight TreeBox control.
Definition: TreeBox.h:81
Root base class for all user interface objects.
Definition: UIObject.h:95
PCL root namespace.
Definition: AbstractImage.h:77