Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfDictionary


      Hashtable<PdfReference,Object> cache = reference.getIndirectObject().getFile().getDocument().cache;
      if(cache.containsKey(reference))
        return (Font)cache.get(reference);
    }

    PdfDictionary fontDictionary = (PdfDictionary)reference.getDataObject();
    PdfName fontType = (PdfName)fontDictionary.get(PdfName.Subtype);
    if(fontType == null)
      throw new RuntimeException("Font type undefined (reference: " + reference + ")");

    if(fontType.equals(PdfName.Type1)) // Type 1.
    {
      if(!fontDictionary.containsKey(PdfName.FontDescriptor)) // Standard Type 1.
        return new StandardType1Font(reference);
      else // Custom Type 1.
      {
        PdfDictionary fontDescriptor = (PdfDictionary)fontDictionary.resolve(PdfName.FontDescriptor);
        if(fontDescriptor.containsKey(PdfName.FontFile3)
            && ((PdfName)((PdfStream)fontDescriptor.resolve(PdfName.FontFile3)).getHeader().resolve(PdfName.Subtype)).equals(PdfName.OpenType)) // OpenFont/CFF.
          throw new NotImplementedException();
        else // Non-OpenFont Type 1.
          return new Type1Font(reference);
      }
    }
    else if(fontType.equals(PdfName.TrueType)) // TrueType.
      return new TrueTypeFont(reference);
    else if(fontType.equals(PdfName.Type0)) // OpenFont.
    {
      PdfDictionary cidFontDictionary = (PdfDictionary)((PdfArray)fontDictionary.resolve(PdfName.DescendantFonts)).resolve(0);
      PdfName cidFontType = (PdfName)cidFontDictionary.get(PdfName.Subtype);
      if(cidFontType.equals(PdfName.CIDFontType0)) // OpenFont/CFF.
        return new Type0Font(reference);
      else if(cidFontType.equals(PdfName.CIDFontType2)) // OpenFont/TrueType.
        return new Type2Font(reference);
      else
View Full Code Here


    Document context
    )
  {
    super(
      context.getFile(),
      new PdfDictionary(
        new PdfName[]{PdfName.Type},
        new PdfDirectObject[]{PdfName.Font}
        )
      );
    initialize();
View Full Code Here

  */
  @Override
  public Dimension2D getSize(
    )
  {
    PdfDictionary header = getBaseDataObject().getHeader();

    return new Dimension(
      ((PdfInteger)header.get(PdfName.Width)).getRawValue(),
      ((PdfInteger)header.get(PdfName.Height)).getRawValue()
      );
  }
View Full Code Here

        }
      }
    }
    // Default glyph width.
    {
      PdfDictionary descriptor = getDescriptor();
      if(descriptor != null)
      {
        PdfNumber<?> defaultGlyphWidthObject = (PdfNumber<?>)descriptor.get(PdfName.MissingWidth);
        defaultGlyphWidth = (defaultGlyphWidthObject == null ? 0 : (int)Math.round(defaultGlyphWidthObject.getNumberValue()));
      }
    }
  }
View Full Code Here

    Resources resources
    )
  {
    super(context);

    PdfDictionary header = getBaseDataObject().getHeader();
    header.put(PdfName.Subtype,PdfName.Form);
    header.put(PdfName.BBox,new Rectangle(0,0,0,0).getBaseDataObject());

    // No resources collection?
    /* NOTE: Resources collection is mandatory. */
    if(resources == null)
    {resources = new Resources(context);}
    header.put(PdfName.Resources,resources.getBaseObject());
  }
View Full Code Here

    Annotation parent
    )
  {
    super(
      parent.getFile(),
      new PdfDictionary()
      );

    this.parent = parent;
  }
View Full Code Here

          (Unicode value to CID) corresponding to the font's one (character code to CID);
          CIDs are the bridge from character codes to Unicode values.
        */
        BiMap<ByteArray,Integer> ucs2CMap;
        {
          PdfDictionary cidSystemInfo = (PdfDictionary)getCIDFontDictionary().resolve(PdfName.CIDSystemInfo);
          String registry = (String)((PdfTextString)cidSystemInfo.get(PdfName.Registry)).getValue();
          String ordering = (String)((PdfTextString)cidSystemInfo.get(PdfName.Ordering)).getValue();
          String ucs2CMapName = registry + "-" + ordering + "-" + "UCS2";
          ucs2CMap = new BiMap<ByteArray,Integer>(CMap.get(ucs2CMapName));
        }
        if(!ucs2CMap.isEmpty())
        {
View Full Code Here

    {
      glyphIndexes = parser.glyphIndexes;
      glyphKernings = parser.glyphKernings;
      glyphWidths = parser.glyphWidths;

      PdfDictionary baseDataObject = getBaseDataObject();

      // BaseFont.
      baseDataObject.put(PdfName.BaseFont,new PdfName(parser.fontName));

      // Subtype.
      baseDataObject.put(PdfName.Subtype, PdfName.Type0);

      // Encoding.
      baseDataObject.put(PdfName.Encoding, PdfName.IdentityH); //TODO: this is a simplification (to refine later).

      // Descendant font.
      PdfDictionary cidFontDictionary = new PdfDictionary(
        new PdfName[]{PdfName.Type},
        new PdfDirectObject[]{PdfName.Font}
        ); // CIDFont dictionary [PDF:1.6:5.6.3].
      {
        // Subtype.
        PdfName subType;
        switch(parser.outlineFormat)
        {
          case TrueType: subType = PdfName.CIDFontType2; break;
          case CFF: subType = PdfName.CIDFontType0; break;
          default: throw new NotImplementedException();
        }
        cidFontDictionary.put(PdfName.Subtype,subType);

        // BaseFont.
        cidFontDictionary.put(
          PdfName.BaseFont,
          new PdfName(parser.fontName)
          );

        // CIDSystemInfo.
        cidFontDictionary.put(
          PdfName.CIDSystemInfo,
          new PdfDictionary(
            new PdfName[]
            {
              PdfName.Registry,
              PdfName.Ordering,
              PdfName.Supplement
            },
            new PdfDirectObject[]
            {
              new PdfTextString("Adobe"),
              new PdfTextString("Identity"),
              new PdfInteger(0)
            }
            )
          ); // Generic predefined CMap (Identity-H/V (Adobe-Identity-0)) [PDF:1.6:5.6.4].

        // FontDescriptor.
        cidFontDictionary.put(
          PdfName.FontDescriptor,
          load_createFontDescriptor(parser)
          );

        // Encoding.
View Full Code Here

        + "end\n"
        + "%%EndResource\n"
        + "%%EOF"
      );
    PdfStream cmapStream = new PdfStream(cmapBuffer);
    PdfDictionary cmapHead = cmapStream.getHeader();
    cmapHead.put(
      PdfName.Type,
      PdfName.CMap
      );
    cmapHead.put(
      PdfName.CMapName,
      new PdfName("Adobe-Identity-UCS")
      );
    cmapHead.put(
      PdfName.CIDSystemInfo,
      new PdfDictionary(
        new PdfName[]
        {
          PdfName.Registry,
          PdfName.Ordering,
          PdfName.Supplement
View Full Code Here

  */
  private PdfReference load_createFontDescriptor(
    OpenFontParser parser
    )
  {
    PdfDictionary fontDescriptor = new PdfDictionary();
    {
      OpenFontParser.FontMetrics metrics = parser.metrics;

      // Type.
      fontDescriptor.put(
        PdfName.Type,
        PdfName.FontDescriptor
        );
      // FontName.
      fontDescriptor.put(
        PdfName.FontName,
        getBaseDataObject().get(PdfName.BaseFont)
        );
      // Flags [PDF:1.6:5.7.1].
      int flags = 0;
      if(metrics.isFixedPitch)
      {flags |= FlagsEnum.FixedPitch.getCode();}
      if(metrics.isCustomEncoding)
      {flags |= FlagsEnum.Symbolic.getCode();}
      else
      {flags |= FlagsEnum.Nonsymbolic.getCode();}
      fontDescriptor.put(
        PdfName.Flags,
        new PdfInteger(flags)
        );
      // FontBBox.
      fontDescriptor.put(
        PdfName.FontBBox,
        new Rectangle(
          new Point2D.Double(metrics.xMin * metrics.unitNorm, metrics.yMin * metrics.unitNorm),
          new Point2D.Double(metrics.xMax * metrics.unitNorm, metrics.yMax * metrics.unitNorm)
          ).getBaseDataObject()
        );
      // ItalicAngle.
      fontDescriptor.put(
        PdfName.ItalicAngle,
        new PdfReal(metrics.italicAngle)
        );
      // Ascent.
      fontDescriptor.put(
        PdfName.Ascent,
        new PdfReal(
          metrics.ascender == 0
            ? metrics.sTypoAscender * metrics.unitNorm
            : metrics.ascender * metrics.unitNorm
          )
        );
      // Descent.
      fontDescriptor.put(
        PdfName.Descent,
        new PdfReal(
          metrics.descender == 0
            ? metrics.sTypoDescender * metrics.unitNorm
            : metrics.descender * metrics.unitNorm
          )
        );
      // Leading.
      fontDescriptor.put(
        PdfName.Leading,
        new PdfReal(metrics.sTypoLineGap * metrics.unitNorm)
        );
      // CapHeight.
      fontDescriptor.put(
        PdfName.CapHeight,
        new PdfReal(metrics.sCapHeight * metrics.unitNorm)
        );
      // StemV.
      /*
        NOTE: '100' is just a rule-of-thumb value, 'cause I've still to solve the
        'cvt' table puzzle (such a harsh headache!) for TrueType fonts...
        TODO:IMPL TrueType and CFF stemv real value to extract!!!
      */
      fontDescriptor.put(
        PdfName.StemV,
        new PdfInteger(100)
        );
      // FontFile.
  //TODO:IMPL distinguish between truetype (FontDescriptor.FontFile2) and opentype (FontDescriptor.FontFile3 and FontStream.subtype=OpenType)!!!
      PdfReference fontFileReference = getFile().register(
        new PdfStream(
          new PdfDictionary(
            new PdfName[]{PdfName.Subtype},
            new PdfDirectObject[]{PdfName.OpenType}
            ),
          new Buffer(parser.fontData.toByteArray())
          )
        );
      fontDescriptor.put(
        PdfName.FontFile3,
        fontFileReference
        );
    }
    return getFile().register(fontDescriptor);
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfDictionary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.