001/* ===============
002 * SkijaGraphics2D
003 * ===============
004 *
005 * (C)opyright 2021, by Object Refinery Limited.
006 *
007 * The SkijaGraphics2D class has been developed by Object Refinery Limited for
008 * use with Orson Charts (http://www.object-refinery.com/orsoncharts) and
009 * JFreeChart (http://www.jfree.org/jfreechart).  It may be useful for other
010 * code that uses the Graphics2D API provided by Java2D.
011 *
012 * Redistribution and use in source and binary forms, with or without
013 * modification, are permitted provided that the following conditions are met:
014 *   - Redistributions of source code must retain the above copyright
015 *     notice, this list of conditions and the following disclaimer.
016 *   - Redistributions in binary form must reproduce the above copyright
017 *     notice, this list of conditions and the following disclaimer in the
018 *     documentation and/or other materials provided with the distribution.
019 *   - Neither the name of the Object Refinery Limited nor the
020 *     names of its contributors may be used to endorse or promote products
021 *     derived from this software without specific prior written permission.
022 *
023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
026 * ARE DISCLAIMED. IN NO EVENT SHALL OBJECT REFINERY LIMITED BE LIABLE FOR ANY
027 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
028 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
030 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
032 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033 *
034 */
035
036package org.jfree.skija;
037
038import java.awt.*;
039import java.util.function.Function;
040
041/**
042 * Defines the rendering hints that can be used with the {@link SkijaGraphics2D}
043 * class.  There is just one hint defined at present:<br>
044 * <ul>
045 * <li>{@link #KEY_FONT_MAPPING_FUNCTION} that controls whether JavaFX font
046 * metrics or Java2D font metrics are used.</li>
047 * </ul>
048 */
049public final class SkijaHints {
050
051    private SkijaHints() {
052        // no need to instantiate this
053    }
054
055    /**
056     * The key for the hint that provides a font mapper from Java logical fonts to corresponding
057     * physical fonts.  A {@code Function<String, String>} instance (or {@code null}) can be assigned
058     * as the value for this key.
059     */
060    public static final SkijaHints.Key KEY_FONT_MAPPING_FUNCTION
061            = new SkijaHints.Key(0);
062
063    /**
064     * A key for hints used by the {@link SkijaGraphics2D} class.
065     */
066    public static class Key extends RenderingHints.Key {
067
068        /**
069         * Creates a new instance with the specified private key.
070         *
071         * @param privateKey the private key.
072         */
073        public Key(int privateKey) {
074            super(privateKey);
075        }
076
077        /**
078         * Returns {@code true} if {@code val} is a value that is
079         * compatible with this key, and {@code false} otherwise.
080         *
081         * @param val the value.
082         * @return A boolean.
083         */
084        @Override
085        public boolean isCompatibleValue(Object val) {
086            switch (intKey()) {
087                case 0:
088                    return val == null
089                            || val instanceof Function;
090                default:
091                    throw new RuntimeException("Not expected!");
092            }
093        }
094    }
095
096}