001/* =====================================================================
002 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
003 * =====================================================================
004 * 
005 * (C)opyright 2013-2020, by Object Refinery Limited.  All rights reserved.
006 *
007 * Project Info:  http://www.object-refinery.com/orsonpdf/index.html
008 * 
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as published by
011 * the Free Software Foundation, either version 3 of the License, or
012 * (at your option) any later version.
013 *
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
021 * 
022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
023 * Other names may be trademarks of their respective owners.]
024 * 
025 * If you do not wish to be bound by the terms of the GPL, an alternative
026 * commercial license can be purchased.  For details, please see visit the
027 * Orson PDF home page:
028 * 
029 * http://www.object-refinery.com/orsonpdf/index.html
030 * 
031 */
032
033package org.jfree.pdf;
034
035import java.awt.RenderingHints;
036
037/**
038 * Defines the rendering hints that can be used with the {@link PDFGraphics2D} 
039 * class.  There is just one hint defined at present:<br>
040 * <ul>
041 * <li>{@link #KEY_DRAW_STRING_TYPE} that controls how the drawString() methods
042 * generate output (regular text or vector graphics);</li>
043 * </ul>
044 * 
045 * @since 1.5
046 */
047public final class PDFHints {
048
049    private PDFHints() {
050        // no need to instantiate this    
051    }
052    
053    /**
054     * The key for the hint that controls whether strings are rendered as
055     * characters (standard PDF output) or vector graphics (implemented using 
056     * <code>TextLayout</code>).  The latter will result in larger output files 
057     * but permits rendering Unicode characters without font embedding (which is 
058     * not supported by <strong>JFreePDF</strong> at this point).  Valid hint 
059     * values are {@link #VALUE_DRAW_STRING_TYPE_STANDARD} and 
060     * {@link #VALUE_DRAW_STRING_TYPE_VECTOR}.
061     */
062    public static final PDFHints.Key KEY_DRAW_STRING_TYPE = new PDFHints.Key(0);
063    
064    /**
065     * Hint value for <code>KEY_DRAW_STRING_TYPE</code> to specify that strings
066     * should be written to the output using standard PDF text primitives.
067     */
068    public static final Object VALUE_DRAW_STRING_TYPE_STANDARD 
069            = "VALUE_DRAW_STRING_TYPE_STANDARD";
070    
071    /**
072     * Hint value for <code>KEY_DRAW_STRING_TYPE</code> to say that strings
073     * should be written to the output using vector graphics primitives.
074     */
075    public static final Object VALUE_DRAW_STRING_TYPE_VECTOR
076            = "VALUE_DRAW_STRING_TYPE_VECTOR";
077    
078    /**
079     * A key for hints used by the {@link PDFGraphics2D} class.
080     */
081    public static class Key extends RenderingHints.Key {
082
083        public Key(int privateKey) {
084            super(privateKey);    
085        }
086    
087        /**
088         * Returns {@code true} if {@code val} is a value that is
089         * compatible with this key, and {@code false} otherwise.
090         * 
091         * @param val  the value.
092         * 
093         * @return A boolean. 
094         */
095        @Override
096        public boolean isCompatibleValue(Object val) {
097            switch (intKey()) {
098                case 0:
099                    return val == null 
100                            || VALUE_DRAW_STRING_TYPE_STANDARD.equals(val)
101                            || VALUE_DRAW_STRING_TYPE_VECTOR.equals(val);
102                default:
103                    throw new RuntimeException("Not expected!");
104            }
105        }
106    }
107    
108}