/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.pdfbox.pdmodel.font;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.fontbox.FontBoxFont;

/**
 * A cache for system fonts. This allows PDFBox to manage caching for a {@link FontProvider}.
 * PDFBox is free to purge this cache at will.
 *
 * @author John Hewson
 */
public final class FontCache
{
    private final Map<FontInfo, FontBoxFont> cache = new ConcurrentHashMap<FontInfo, FontBoxFont>();

    /**
     * Adds the given FontBox font to the cache.
     */
    public void addFont(FontInfo info, FontBoxFont font)
    {
        cache.put(info, font);
    }

    /**
     * Returns the FontBox font associated with the given FontInfo.
     */
    public FontBoxFont getFont(FontInfo info)
    {
        return cache.get(info);
    }
}

@@ -838,16 +838,52 @@
 .font;%0A%0A
+import java.lang.ref.SoftReference;%0A
 import j
@@ -892,24 +892,24 @@
 a.util.Map;%0A
-
 import java.
@@ -1213,32 +1213,46 @@
 l Map%3CFontInfo, 
+SoftReference%3C
 FontBoxFont%3E cac
@@ -1251,16 +1251,17 @@
 ont%3E
+%3E
  cache =
  new
@@ -1256,16 +1256,28 @@
  cache =
+%0A           
  new Con
@@ -1297,24 +1297,38 @@
 p%3CFontInfo, 
+SoftReference%3C
 FontBoxFont%3E
@@ -1327,16 +1327,17 @@
 BoxFont%3E
+%3E
 ();%0A%0A   
@@ -1485,21 +1485,53 @@
 t(info, 
+new SoftReference%3CFontBoxFont%3E(
 font)
+)
 ;%0A    %7D%0A
@@ -1659,32 +1659,32 @@
 nfo info)%0A    %7B%0A
-
         return c
@@ -1697,16 +1697,22 @@
 et(info)
+.get()
 ;%0A    %7D%0A

Use SoftReference for FontCache