casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DLFont.h
Go to the documentation of this file.
00001 //# DLFont.h : Class to provide encapsulation for fonts
00002 //# Copyright (C) 2000,2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id:
00027 
00028 
00029 #ifndef TRIALDISPLAY_DLFONT_H
00030 #define TRIALDISPLAY_DLFONT_H
00031 
00032 #include <casa/BasicSL/String.h>
00033 #include <casa/Exceptions.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // A class designed to manage several representations of the same font
00039 // </summary>
00040 
00041 // <use visibility=export>
00042 
00043 // <reviewed reviewer="" date="" test="" demos="">
00044 // </reviewed>
00045 
00046 // <prerequisite>
00047 // </prerequisite>
00048 
00049 // <etymology>
00050 // DLFont is a class designed to manage multiple representations of the 
00051 // same font.
00052 // </etymology>
00053 
00054 // <motivation>
00055 // Different DL media (e.g. X11 and postscript) have different ways of 
00056 // representing fonts. The user, however should be presented with a single
00057 // representation across all media types. This class is designed to represent
00058 // a single font, as observed by the user, but also to contain different 
00059 // representations of the font for each media.
00060 // </motivation>
00061 
00062 // <thrown>
00063 // <li> None.
00064 // </thrown>
00065 
00066 // <todo asof="2002/05/13">
00067 // <li> Nothing known.
00068 // </todo>
00069 
00070 class DLFont {
00071 
00072  public:
00073   enum FontDescription{ Name, XFontDescription, PSFontName };
00074 
00075   // (Required) default constructor.
00076   DLFont();
00077 
00078   // The constructor accepts any description of the font. By default it is
00079   // the 'name' of the font. You can also construct a DLFont by either of
00080   // its other descriptions, by using the appropriate 'FontDescription'.
00081   // e.g to select Times by its PostScript name:
00082   // <srcblock>
00083   // DLFont myFont("Times-Roman", DLFont::PSFontName);
00084   // </srcblock> 
00085   // is equivalent to :
00086   // <srcblock>
00087   // DLFont myFont("-adobe-times-medium-r-*--*", DLFont::XFontDescription);
00088   // </srcblock>
00089   // or, more simply :
00090   // <srcblock>
00091   // DLFont myFont("Times - Roman");
00092   // </srcblock>
00093   DLFont(const String& description, 
00094          const DLFont::FontDescription whatType = DLFont::Name,
00095          const Int& size = 12);
00096 
00097   // Copy constructor using copy semantics.
00098   DLFont(const DLFont& other);
00099 
00100   // Destructor.
00101   virtual ~DLFont();
00102 
00103   // Copy assignment.
00104   DLFont &operator=(const DLFont &other);
00105 
00106   // Return the current font as a XLFD. Although it states "noSize", it may
00107   // actually return a size. e.g. a call to "setXValue", providing
00108   // an entry in the size field will result in a XLFD with a valid size field.
00109   // However, if you do a "setSize", then call this method, the change in 
00110   // size will not be reflected. 
00111   String getXValueNoSize();
00112 
00113   // Return the current font as a post-script recognisable name
00114   //  String getPSValueNoSize();
00115   
00116   // Return the current fonts desired size
00117   Int getSize();
00118 
00119   // Return the current font as a XLFD, with the specific size.
00120   // NB If there is any matrix transform in the pixel size field
00121   // of the XLFD, this will not preserve it. To do operations
00122   // e.g. rotation, extract the desired font size (getSize) and the 
00123   // font info (getXFontNoSize) seperately before applying required
00124   // transforms
00125   String getXValue();
00126 
00127   // Return the current font as a PS recognisable name, with the specific size
00128   // 'tagged onto' the end of it.
00129   String getPSValue();
00130 
00131   // Return the name (as it should be presented to users) of the font.
00132   String getName();
00133 
00134   // Set the name of the font
00135   void setName(const String& newName);
00136 
00137   // Set the desired size (pixelSize) 
00138   void setSize(const Int newSize);
00139 
00140   // Set the XLFD for this font (if you wish to set at matrix for any fields
00141   // e.g. set the size field as a rotation matrix to rotate text, you will
00142   // need to handle the size of the text independantly of this class. 
00143   // You can use the getXValueNoSize for that. i.e. class will not 
00144   // preserve rotated/scaled text via matrix transforms
00145   void setXValue(const String& newX11);
00146   
00147   // Set the Postscript representation of this font
00148   void setPSValue(const String& newPS);
00149 
00150   Vector<String> getAllNames() {
00151     return itsNames;
00152   }
00153 
00154 protected:
00155 
00156 
00157 private:
00158   void fillArrays();
00159   Bool lookUp(const String& desc, const DLFont::FontDescription, 
00160               Int& returnIndex);
00161 
00162   Vector<String> itsXFonts;
00163   Vector<String> itsPSFonts;
00164   Vector<String> itsNames;
00165   
00166   Int itsSize;
00167   Int itsCurrentFont;
00168 };
00169 
00170 
00171 } //# NAMESPACE CASA - END
00172 
00173 #endif
00174 
00175 
00176 
00177