private void populateDictionary()

in fop-core/src/main/java/org/apache/fop/pdf/PDFResources.java [225:338]


    private void populateDictionary() {
        if (parent != null && parent.fontsObj != null) {
            put("Font", parent.fontsObj);
        }
        if (!this.fonts.isEmpty() || (parent != null && !parent.fonts.isEmpty())) {
            PDFDictionary dict = new PDFDictionary(this);
            /* construct PDF dictionary of font object references */
            for (Map.Entry<String, PDFDictionary> entry : fonts.entrySet()) {
                dict.put(entry.getKey(), entry.getValue());
            }
            if (parent != null) {
                for (Map.Entry<String, PDFDictionary> entry : parent.fonts.entrySet()) {
                    dict.put(entry.getKey(), entry.getValue());
                }
                for (Map.Entry<String, PDFDictionary> entry : parent.fontsObjDict.entrySet()) {
                    dict.put(entry.getKey(), entry.getValue());
                }
            }
            put("Font", dict);
        }

        Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
        Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
        Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
        for (PDFResourceContext c : contexts) {
            xObjects.addAll(c.getXObjects());
            patterns.addAll(c.getPatterns());
            shadings.addAll(c.getShadings());
            gstates.addAll(c.getGStates());
        }
        if (parent != null) {
            xObjects.addAll(parent.xObjects);
            for (PDFResourceContext c : parent.contexts) {
                patterns.addAll(c.getPatterns());
                shadings.addAll(c.getShadings());
                gstates.addAll(c.getGStates());
            }
        }

        if (!shadings.isEmpty()) {
            PDFDictionary dict = (PDFDictionary) get("Shading");
            if (dict == null) {
                dict = new PDFDictionary(this);
            }
            for (PDFShading shading : shadings) {
                dict.put(shading.getName(), shading);
            }
            put("Shading", dict);
        }

        if (!patterns.isEmpty()) {
            PDFDictionary dict = (PDFDictionary) get("Pattern");
            if (dict == null) {
                dict = new PDFDictionary(this);
            }
            for (PDFPattern pattern : patterns) {
                dict.put(pattern.getName(), pattern);
            }
            put("Pattern", dict);
        }

        PDFArray procset = new PDFArray(this);
        procset.add(new PDFName("PDF"));
        procset.add(new PDFName("ImageB"));
        procset.add(new PDFName("ImageC"));
        procset.add(new PDFName("Text"));
        put("ProcSet", procset);

        if (!xObjects.isEmpty()) {
            PDFDictionary dict = (PDFDictionary) get("XObject");
            if (dict == null) {
                dict = new PDFDictionary(this);
            }
            for (PDFXObject xObject : xObjects) {
                dict.put(xObject.getName().toString(), xObject);
            }
            put("XObject", dict);
        }

        if (!gstates.isEmpty()) {
            PDFDictionary dict = (PDFDictionary) get("ExtGState");
            if (dict == null) {
                dict = new PDFDictionary(this);
            }
            for (PDFGState gstate : gstates) {
                dict.put(gstate.getName(), gstate);
            }
            put("ExtGState", dict);
        }

        if (!this.colorSpaces.isEmpty() || (parent != null && !parent.colorSpaces.isEmpty())) {
            PDFDictionary dict = (PDFDictionary)this.get("ColorSpace");
            if (dict == null) {
                dict = new PDFDictionary(this);
            }
            if (parent != null) {
                for (PDFColorSpace colorSpace : parent.colorSpaces.values()) {
                    dict.put(colorSpace.getName(), colorSpace);
                }
            }
            for (PDFColorSpace colorSpace : colorSpaces.values()) {
                dict.put(colorSpace.getName(), colorSpace);
            }
            put("ColorSpace", dict);
        }

        if (!properties.isEmpty()) {
            PDFDictionary dict = new PDFDictionary(this);
            for (Map.Entry<String, PDFReference> stringPDFReferenceEntry : properties.entrySet()) {
                dict.put(stringPDFReferenceEntry.getKey(), stringPDFReferenceEntry.getValue());
            }
            put("Properties", dict);
        }
    }