001/* =====================================================================
002 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
003 * =====================================================================
004 *
005 * (C)opyright 2013-2022, by David Gilbert.  All rights reserved.
006 *
007 * https://github.com/jfree/orsonpdf
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 * runtime license is available to JFree sponsors:
027 *
028 * https://github.com/sponsors/jfree
029 *
030 */
031
032package org.jfree.pdf;
033
034import java.awt.RenderingHints;
035
036/**
037 * Defines the rendering hints that can be used with the {@link PDFGraphics2D} 
038 * class.  There is just one hint defined at present:<br>
039 * <ul>
040 * <li>{@link #KEY_DRAW_STRING_TYPE} that controls how the drawString() methods
041 * generate output (regular text or vector graphics);</li>
042 * </ul>
043 * 
044 * @since 1.5
045 */
046public final class PDFHints {
047
048    private PDFHints() {
049        // no need to instantiate this    
050    }
051    
052    /**
053     * The key for the hint that controls whether strings are rendered as
054     * characters (standard PDF output) or vector graphics (implemented using 
055     * <code>TextLayout</code>).  The latter will result in larger output files 
056     * but permits rendering Unicode characters without font embedding (which is 
057     * not supported by <strong>JFreePDF</strong> at this point).  Valid hint 
058     * values are {@link #VALUE_DRAW_STRING_TYPE_STANDARD} and 
059     * {@link #VALUE_DRAW_STRING_TYPE_VECTOR}.
060     */
061    public static final PDFHints.Key KEY_DRAW_STRING_TYPE = new PDFHints.Key(0);
062    
063    /**
064     * Hint value for <code>KEY_DRAW_STRING_TYPE</code> to specify that strings
065     * should be written to the output using standard PDF text primitives.
066     */
067    public static final Object VALUE_DRAW_STRING_TYPE_STANDARD 
068            = "VALUE_DRAW_STRING_TYPE_STANDARD";
069    
070    /**
071     * Hint value for <code>KEY_DRAW_STRING_TYPE</code> to say that strings
072     * should be written to the output using vector graphics primitives.
073     */
074    public static final Object VALUE_DRAW_STRING_TYPE_VECTOR
075            = "VALUE_DRAW_STRING_TYPE_VECTOR";
076    
077    /**
078     * A key for hints used by the {@link PDFGraphics2D} class.
079     */
080    public static class Key extends RenderingHints.Key {
081
082        /**
083         * Creates a new instance with the specified key.
084         * 
085         * @param privateKey  the key.
086         */
087        public Key(int privateKey) {
088            super(privateKey);    
089        }
090    
091        /**
092         * Returns {@code true} if {@code val} is a value that is
093         * compatible with this key, and {@code false} otherwise.
094         * 
095         * @param val  the value.
096         * 
097         * @return A boolean. 
098         */
099        @Override
100        public boolean isCompatibleValue(Object val) {
101            switch (intKey()) {
102                case 0:
103                    return val == null 
104                            || VALUE_DRAW_STRING_TYPE_STANDARD.equals(val)
105                            || VALUE_DRAW_STRING_TYPE_VECTOR.equals(val);
106                default:
107                    throw new RuntimeException("Not expected!");
108            }
109        }
110    }
111    
112}