PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PFont.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/objects/PFont.h
4// Purpose: Contains generic specs for a font
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PFONT_H__
28#define __PFONT_H__
29
30
31#include "PWidget.h"
32#include "PColor.h"
33#include <string>
34#include "../utility/rc_ptrs.h"
35#include "../base/PEBLObject.h"
36
42
44 {
45 PFS_Normal = 0x00,
46 PFS_Bold = 0x01,
47 PFS_Italic = 0x02,
48 PFS_Underline = 0x04
49 };
50
51
52class PFont: virtual public PEBLObjectBase
53{
54public:
55
57 PFont();
58 PFont(const std::string & filename);
59 PFont(const std::string & filename, int style, int size,
60 PColor fgcolor, PColor bgcolor, bool aa);
61 PFont(const PFont & font);
62 virtual ~PFont();
63
64 //overloaded generic PObject methods
65 virtual bool SetProperty(std::string, Variant v);
66 virtual Variant GetProperty(std::string)const;
67 virtual ObjectValidationError ValidateProperty(std::string, Variant v)const;
68 virtual ObjectValidationError ValidateProperty(std::string)const;
69
70 virtual std::string ObjectName() const;
71
73 virtual void SetFontFileName(const std::string & name);
74 virtual void SetFontStyle(const int style);
75 virtual void SetFontSize(const int size);
76 virtual void SetFontColor(PColor color);
77 virtual void SetBackgroundColor(PColor color);
78 virtual void SetAntiAliased(const bool aa);
79
80
81
82 //Get methods for all of the data in font
83 virtual std::string GetFontFileName() const {return mFontFileName;};
84 virtual int GetFontStyle() const {return mFontStyle;};
85 virtual int GetFontSize() const {return mFontSize;};
86 virtual PColor GetFontColor() const;
87 virtual PColor GetBackgroundColor() const;
88 virtual bool GetAntiAliased() const {return mAntiAliased;};
89
90
91 //These get different styles
92 virtual bool IsNormalFont() const;
93 virtual bool IsBoldFont() const;
94 virtual bool IsItalicFont() const;
95 virtual bool IsUnderlineFont() const;
96
97protected:
98 virtual std::ostream & SendToStream(std::ostream& out) const;
99
100 // Helper methods to get color pointers from property system (like PDrawObject)
101 PColor* GetFontColorPtr() const;
103
104 std::string mFontFileName; // Filename of font file.
105 int mFontStyle; // Bold, underlined, italics, normal, etc. These use PFontStyle constants or'ed together
106 int mFontSize; // Size, in 'points'
107
108 // Colors are stored ONLY in property map (like PDrawObject, PCanvas, PWindow)
109 // No member variables - eliminates double ownership bug
110 bool mAntiAliased; // Whether the text is anti-aliased, alpha-blended with background (slow but nice)
111};
112
113
114#endif
ObjectValidationError
Definition PEBLObject.h:37
PFontStyle
Definition PFont.h:44
@ PFS_Underline
Definition PFont.h:48
@ PFS_Normal
Definition PFont.h:45
@ PFS_Bold
Definition PFont.h:46
@ PFS_Italic
Definition PFont.h:47
Definition PFont.h:53
virtual void SetFontColor(PColor color)
Definition PFont.cpp:303
PColor * GetBackgroundColorPtr() const
Definition PFont.cpp:280
PColor * GetFontColorPtr() const
Definition PFont.cpp:272
int mFontStyle
Definition PFont.h:105
PFont(const std::string &filename)
virtual PColor GetBackgroundColor() const
Definition PFont.cpp:296
virtual Variant GetProperty(std::string) const
Definition PFont.cpp:228
virtual void SetFontStyle(const int style)
Definition PFont.cpp:257
virtual int GetFontStyle() const
Definition PFont.h:84
virtual void SetBackgroundColor(PColor color)
Definition PFont.cpp:315
int mFontSize
Definition PFont.h:106
virtual ~PFont()
Copy constructor.
Definition PFont.cpp:151
PFont()
Standard constructors:
Definition PFont.cpp:39
virtual bool IsItalicFont() const
Definition PFont.cpp:373
virtual void SetFontSize(const int size)
Definition PFont.cpp:265
virtual PColor GetFontColor() const
Definition PFont.cpp:289
virtual void SetAntiAliased(const bool aa)
Definition PFont.cpp:327
virtual std::string GetFontFileName() const
Definition PFont.h:83
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PFont.cpp:234
virtual std::string ObjectName() const
Definition PFont.cpp:243
std::string mFontFileName
Definition PFont.h:104
virtual bool IsUnderlineFont() const
Definition PFont.cpp:379
virtual bool IsBoldFont() const
Definition PFont.cpp:367
virtual bool GetAntiAliased() const
Definition PFont.h:88
bool mAntiAliased
Definition PFont.h:110
virtual int GetFontSize() const
Definition PFont.h:85
virtual std::ostream & SendToStream(std::ostream &out) const
This sends the font descriptions to the specified stream.
Definition PFont.cpp:336
virtual void SetFontFileName(const std::string &name)
Set methods for all of the data in font.
Definition PFont.cpp:251
virtual bool SetProperty(std::string, Variant v)
Standard Destructors.
Definition PFont.cpp:158
virtual bool IsNormalFont() const
Definition PFont.cpp:362