1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17/**
18 * @author Alexey A. Petrenko, Ilya S. Okomin
19 * @version $Revision$
20 */
21package org.apache.harmony.awt.gl;
22
23import java.awt.Font;
24import java.awt.FontMetrics;
25import java.awt.peer.FontPeer;
26
27import org.apache.harmony.awt.gl.font.FontMetricsImpl;
28import org.apache.harmony.awt.wtk.GraphicsFactory;
29
30/**
31 * Common GraphicsFactory implementation
32 *
33 */
34public abstract class CommonGraphics2DFactory implements GraphicsFactory {
35
36    // static instance of CommonGraphics2DFactory
37    public static CommonGraphics2DFactory inst;
38
39    /**
40     * Returns FontMetrics object that keeps metrics of the specified font.
41     *
42     * @param font specified Font
43     * @return FontMetrics object corresponding to the specified Font object
44     */
45    public FontMetrics getFontMetrics(Font font) {
46        FontMetrics fm;
47        for (FontMetrics element : cacheFM) {
48            fm = element;
49            if (fm == null){
50                break;
51            }
52
53            if (fm.getFont().equals(font)){
54                return fm;
55            }
56        }
57        fm = new FontMetricsImpl(font);
58
59        System.arraycopy(cacheFM, 0, cacheFM, 1, cacheFM.length -1);
60        cacheFM[0] = fm;
61
62        return fm;
63    }
64    // Font methods
65
66    public FontPeer getFontPeer(Font font) {
67        return getFontManager().getFontPeer(font.getName(), font.getStyle(), font.getSize());
68    }
69
70    /**
71     * Embeds font from gile with specified path into the system.
72     *
73     * @param fontFilePath path to the font file
74     * @return Font object that was created from the file.
75     */
76    public abstract Font embedFont(String fontFilePath);
77
78}