001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030/**
031 * 
032 */
033package org.openimaj.image.typography.general;
034
035import org.openimaj.image.renderer.ImageRenderer;
036import org.openimaj.image.typography.Font;
037import org.openimaj.image.typography.FontRenderer;
038import org.openimaj.image.typography.FontStyle;
039
040/**
041 *      This is a wrapper for the Java AWT Font in the OpenIMAJ system.
042 *      To use this font, use something like the following:
043 *      <pre>{@code
044 *              MBFImage img = new MBFImage( 400, 400, 3 );
045 *              GeneralFont f = new GeneralFont( "Times New Roman", Font.PLAIN, 72 );
046 *              img.drawText( "Hello World", new Point2dImpl(10,500),
047 *                      new GeneralFontStyle( f, r, true ) );
048 *      }</pre>
049 *
050 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
051 *  @created 18 Aug 2011
052 *      
053 */
054public class GeneralFont implements Font<GeneralFont>
055{
056        private final String name;
057        private int type;
058        //      private float size;
059
060        /**
061         *      Create a font with the given name, type and size. The name
062         *      should be the name of the font on your system. The type should
063         *      be Font.PLAIN, Font.BOLD or other Font attributes.
064         *      This is the same as the constructor
065         *      for the java.awt.Font class.
066         * 
067         *      @param name Name of the font
068         *      @param type Font attributes
069         */
070        public GeneralFont( final String name, final int type )
071        {
072                this.name = name;
073                this.setType( type );
074        }
075
076        /**
077         *      {@inheritDoc}
078         *      @see org.openimaj.image.typography.Font#getRenderer(org.openimaj.image.renderer.ImageRenderer)
079         */
080        @SuppressWarnings( "unchecked" )
081        @Override
082        public <T, Q extends FontStyle<T>> FontRenderer<T, Q>
083        getRenderer( final ImageRenderer<T, ?> renderer )
084        {
085                return (FontRenderer<T, Q>)(Object)new GeneralFontRenderer<T>();
086        }
087
088        /**
089         *      {@inheritDoc}
090         *      @see org.openimaj.image.typography.Font#createStyle(org.openimaj.image.renderer.ImageRenderer)
091         */
092        @Override
093        public <T> FontStyle< T>
094        createStyle( final ImageRenderer<T, ?> renderer )
095        {
096                return new GeneralFontStyle<T>( this, renderer );
097        }
098
099        /**
100         *      {@inheritDoc}
101         *      @see org.openimaj.image.typography.Font#getName()
102         */
103        @Override
104        public String getName()
105        {
106                return this.name;
107        }
108
109        /**
110         *      Set the type of the font.
111         * 
112         *      @param type the type of the font.
113         */
114        public void setType( final int type )
115        {
116                this.type = type;
117        }
118
119        /**
120         *      Get the font attributes
121         *      @return the font attributes
122         */
123        public int getType()
124        {
125                return this.type;
126        }
127}