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: PSFontResource.java 1352986 2012-06-22 18:07:04Z vhennebert $ */
19 
20 package org.apache.fop.render.ps;
21 
22 import org.apache.xmlgraphics.ps.PSResource;
23 import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
24 
25 /**
26  * A DSC resource corresponding to a font. This class handles the possible other resources
27  * that a font may depend on. For example, a CID-keyed font depends on a CIDFont resource, a
28  * CMap resource, and the ProcSet CIDInit resource.
29  */
30 abstract class PSFontResource {
31 
createFontResource(final PSResource fontResource)32     static PSFontResource createFontResource(final PSResource fontResource) {
33         return new PSFontResource() {
34 
35             String getName() {
36                 return fontResource.getName();
37             }
38 
39             void notifyResourceUsageOnPage(ResourceTracker resourceTracker) {
40                 resourceTracker.notifyResourceUsageOnPage(fontResource);
41             }
42         };
43     }
44 
45     static PSFontResource createFontResource(final PSResource fontResource,
46             final PSResource procsetCIDInitResource, final PSResource cmapResource,
47             final PSResource cidFontResource) {
48         return new PSFontResource() {
49 
50             String getName() {
51                 return fontResource.getName();
52             }
53 
54             void notifyResourceUsageOnPage(ResourceTracker resourceTracker) {
55                 resourceTracker.notifyResourceUsageOnPage(fontResource);
56                 resourceTracker.notifyResourceUsageOnPage(procsetCIDInitResource);
57                 resourceTracker.notifyResourceUsageOnPage(cmapResource);
58                 resourceTracker.notifyResourceUsageOnPage(cidFontResource);
59             }
60         };
61     }
62 
63     /**
64      * Returns the name of the font resource.
65      *
66      * @return the name of the font
67      */
68     abstract String getName();
69 
70     /**
71      * Notifies the given resource tracker of all the resources needed by this font.
72      *
73      * @param resourceTracker
74      */
75     abstract void notifyResourceUsageOnPage(ResourceTracker resourceTracker);
76 
77 }
78