001package com.hfg.graphics;
002
003
004
005import java.awt.Font;
006
007import com.hfg.exception.ProgrammingException;
008import com.hfg.util.StringBuilderPlus;
009
010//------------------------------------------------------------------------------
011/**
012 Font-related utility functions.
013 @author J. Alex Taylor, hairyfatguy.com
014 */
015//------------------------------------------------------------------------------
016// com.hfg XML/HTML Coding Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public class FontUtil
037{
038
039   //##########################################################################
040   // PUBLIC FUNCTIONS
041   //##########################################################################
042
043   //--------------------------------------------------------------------------
044   public static String encode(Font inFont)
045   {
046      String style;
047      switch (inFont.getStyle())
048      {
049         case Font.PLAIN:
050            style = "PLAIN";
051            break;
052         case Font.BOLD:
053            style = "BOLD";
054            break;
055         case Font.ITALIC:
056            style = "ITALIC";
057            break;
058         case 3:
059            style = "BOLDITALIC";
060            break;
061         default:
062            throw new ProgrammingException("Unexpected Font style: " + inFont.getStyle() + "!");
063      }
064
065      StringBuilderPlus stringValue = new StringBuilderPlus().setDelimiter("-");
066
067      stringValue.append(inFont.getName())
068            .delimitedAppend(style)
069            .delimitedAppend(inFont.getSize());
070
071      return stringValue.toString();
072   }
073}