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 /* $Id: AFPPageFonts.java 1297404 2012-03-06 10:17:54Z vhennebert $ */
19 
20 package org.apache.fop.afp.fonts;
21 
22 /**
23  * Holds the current page fonts
24  */
25 public class AFPPageFonts extends java.util.HashMap {
26     private static final long serialVersionUID = -4991896259427109041L;
27 
28     /**
29      * Default constructor
30      */
AFPPageFonts()31     public AFPPageFonts() {
32         super();
33     }
34 
35     /**
36      * Parameterized constructor
37      *
38      * @param fonts an existing set of afp page fonts
39      */
AFPPageFonts(AFPPageFonts fonts)40     public AFPPageFonts(AFPPageFonts fonts) {
41         super(fonts);
42     }
43 
44     /**
45      * Registers a font on the current page and returns font attributes
46      *
47      * @param fontName the internal font name
48      * @param font the AFPFont
49      * @param fontSize the font point size
50      * @return newly registered AFPFontAttributes
51      */
registerFont(String fontName, AFPFont font, int fontSize)52     public AFPFontAttributes registerFont(String fontName, AFPFont font, int fontSize) {
53         String pageFontKey = fontName + "_" + fontSize;
54         AFPFontAttributes afpFontAttributes = (AFPFontAttributes)super.get(pageFontKey);
55         // Add to page font mapping if not already present
56         if (afpFontAttributes == null) {
57             afpFontAttributes = new AFPFontAttributes(fontName, font, fontSize);
58             super.put(pageFontKey, afpFontAttributes);
59             int fontRef = super.size();
60             afpFontAttributes.setFontReference(fontRef);
61         }
62         return afpFontAttributes;
63     }
64 }
65