001/* ===============
002 * SkijaGraphics2D
003 * ===============
004 *
005 * (C)opyright 2021, by David Gilbert.
006 *
007 * The SkijaGraphics2D class has been developed by David Gilbert 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 io.github.humbleui.skija.FontStyle;
039
040/**
041 * A key used to identify a {@code Typeface} in a map used to cache items.
042 */
043public class TypefaceKey {
044
045    private final String fontName;
046
047    private final FontStyle style;
048
049    /**
050     * Creates a new key.
051     *
052     * @param fontName  the font name.
053     * @param style  the style.
054     */
055    public TypefaceKey(String fontName, FontStyle style) {
056        this.fontName = fontName;
057        this.style = style;
058    }
059
060    /**
061     * Returns the font name.
062     *
063     * @return The font name.
064     */
065    public String getFontName() {
066        return fontName;
067    }
068
069    /**
070     * Returns the font style.
071     *
072     * @return The font style.
073     */
074    public FontStyle getStyle() {
075        return style;
076    }
077
078    @Override
079    public boolean equals(Object o) {
080        if (this == o) return true;
081        if (o == null || getClass() != o.getClass()) return false;
082
083        TypefaceKey that = (TypefaceKey) o;
084
085        if (!fontName.equals(that.fontName)) return false;
086        return style.equals(that.style);
087    }
088
089    @Override
090    public int hashCode() {
091        int result = fontName.hashCode();
092        result = 31 * result + style.hashCode();
093        return result;
094    }
095}