Exemple #1
0
void
Tfm::Read ()
{
  if (! dviChars.empty() || dviInfo.notLoadable)
    {
      return;
    }

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("going to load TFM file %s"),
     dviInfo.name.c_str());

  PathName fileName;

  bool tfmFileExists =
    SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(),
				      fileName,
				      false);

  if (! tfmFileExists)
    {
      if (Make(dviInfo.name))
	{
	  tfmFileExists =
	    SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(),
					      fileName,
					      false);
	  if (! tfmFileExists)
	    {
	      // this shouldn't happen; but it does (#521481)
	    }
	}
      if (! tfmFileExists)
	{
	  dviInfo.transcript += "\r\n";
	  dviInfo.transcript += T_("Loading 'cmr10' instead.\r\n");
	  trace_error->WriteFormattedLine
	    ("libdvi",
	     T_("'%s' not loadable - loading 'cmr10' instead!"),
	     dviInfo.name.c_str());
	  if (! (SessionWrapper(true)->FindTfmFile("cmr10",
						   fileName,
						   false)
		 || (Make("cmr10")
		     && SessionWrapper(true)->FindTfmFile("cmr10",
							  fileName,
							  false))))
	    {
	      dviInfo.transcript += T_("'cmr10' not loadable either!");
	      trace_error->WriteLine
		("libdvi",
		 T_("'cmr10' not loadable - will display blank chars!"));
	      return;
	    }
	}
    }

  dviInfo.fileName = fileName.ToString();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("opening TFM file %s"),
     fileName.Get());

  InputStream inputStream (fileName.Get());

  long lf = inputStream.ReadSignedPair();

  if (lf == 0)
    {
      FATAL_DVI_ERROR ("Tfm::Read",
		       T_("Invalid TFM file."),
		       0);
    }

  long lh = inputStream.ReadSignedPair();
  long bc = inputStream.ReadSignedPair();
  long ec = inputStream.ReadSignedPair();
  long nw = inputStream.ReadSignedPair();
  long nh = inputStream.ReadSignedPair();
  long nd = inputStream.ReadSignedPair();
  long ni = inputStream.ReadSignedPair();
  long nl = inputStream.ReadSignedPair();
  long nk = inputStream.ReadSignedPair();
  long ne = inputStream.ReadSignedPair();
  long np = inputStream.ReadSignedPair();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("header size: %ld"),
     lh);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("smallest character code: %ld"),
     bc);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("largest character code: %ld"),
     ec);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("width table size: %ld"),
     nw);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("height table size: %ld"),
     nh);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("depth table size: %ld"),
     nd);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("italic correction table size: %ld"),
     ni);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("lig/kern table size: %ld"),
     nl);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("kern table size: %ld"),
     nk);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("extensible character table size: %ld"),
     ne);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("font parameter size: %ld"),
     np);

  int my_checkSum = inputStream.ReadSignedQuad();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     "checkSum: 0%lo",
     my_checkSum);
  
  int my_designSize = inputStream.ReadSignedQuad();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     "designSize: %ld",
     my_designSize);

  if (my_checkSum != checkSum)
    {
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%s: checkSum mismatch"),
	 dviInfo.name.c_str());
    }

  if (my_designSize * tfmConv != designSize)
    {
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%s: designSize mismatch"),
	 dviInfo.name.c_str());
    }

  inputStream.SkipBytes ((lh - 2) * 4);

  struct TfmIndex
  {
    int widthIndex;
    int heightIndex;
    int depthIndex;
  };

  vector<TfmIndex> infoTable (ec);

  for (int charCode = bc; charCode < ec; ++ charCode)
    {
      DviChar * pDviChar = new DviChar (this);
      dviChars[charCode] = pDviChar;
      pDviChar->SetCharacterCode (charCode);
      TfmIndex tfmIndex;
      tfmIndex.widthIndex = inputStream.ReadSignedByte();
      int heightDepth = inputStream.ReadSignedByte();
      tfmIndex.heightIndex = ((heightDepth >> 4) & 15);
      tfmIndex.depthIndex = (heightDepth & 15);
      inputStream.SkipBytes (2);
      infoTable[charCode] = tfmIndex;
    }

  vector<int> widths (nw);

  for (int idx = 0; idx < nw; ++ idx)
    {
      widths[idx] = inputStream.ReadSignedQuad();
    }

  vector<int> heights (nh);

  for (int idx = 0; idx < nh; ++ idx)
    {
      heights[idx] = inputStream.ReadSignedQuad();
    }

  vector<int> depths (nd);

  for (int idx = 0; idx < nd; ++ idx)
    {
      depths[idx] = inputStream.ReadSignedQuad();
    }

  // inputStream.Close ();

  for (int charCode = bc; charCode < ec; ++ charCode)
    {
      int tfmWidth =
	ScaleFix(widths[infoTable[charCode].widthIndex], GetScaledAt());
      dviChars[charCode]->SetDviWidth (tfmWidth);
      int pixelWidth;
      if (tfmWidth >= 0)
	{
	  pixelWidth = static_cast<int>(conv * tfmWidth + 0.5);
	}
      else
	{
	  pixelWidth = - static_cast<int>(conv * -tfmWidth + 0.5);
	}
      dviChars[charCode]->SetWidth (pixelWidth);
    }
}
Exemple #2
0
void
PkChar::Read (/*[in]*/ InputStream &	inputstream,
	      /*[in]*/ int		flag)
{
  this->flag = flag;

  if (IsShort())
    {
      // read character preamble (short form)
      packetSize = (((static_cast<int>(GetLower3()) % 4) << 8
		     | inputstream.ReadByte())
		    - 8);
      charCode = inputstream.ReadByte();
      tfm = inputstream.ReadTrio();
      cx = inputstream.ReadByte();
      rasterWidth = inputstream.ReadByte();
      rasterHeight = inputstream.ReadByte();
      cxOffset = inputstream.ReadSignedByte();
      cyOffset = inputstream.ReadSignedByte();
    }
  else if (IsExtendedShort())
    {
      // read character preamble (extended short form)
      packetSize = (((static_cast<int>(GetLower3()) % 4) << 16
		     | inputstream.ReadPair())
		    - 13);
      charCode = inputstream.ReadByte();
      tfm = inputstream.ReadTrio();
      cx = inputstream.ReadPair();
      rasterWidth = inputstream.ReadPair(); 
      rasterHeight = inputstream.ReadPair(); 
      cxOffset = inputstream.ReadSignedPair();
      cyOffset = inputstream.ReadSignedPair();
    }
  else
    {
      // read character preamble (long form)
      packetSize = inputstream.ReadSignedQuad() - 28;
      charCode = inputstream.ReadSignedQuad();
      tfm = inputstream.ReadSignedQuad();
      cx = inputstream.ReadSignedQuad();
      cx = (cx + 0x10000) >> 16;
      cy = inputstream.ReadSignedQuad();
      cy = (cy + 0x10000) >> 16;
      rasterWidth = inputstream.ReadSignedQuad();
      rasterHeight = inputstream.ReadSignedQuad();
      cxOffset = inputstream.ReadSignedQuad();
      cyOffset = inputstream.ReadSignedQuad();
    }

  tfm = ScaleFix(tfm, pDviFont->GetScaledAt());

  if (packetSize == 0)
    {
#if 0
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%d: no glyph!"),
	 charCode);
#endif
    }
  else
    {
      trace_pkchar->WriteFormattedLine
	("libdvi",
	 T_("going to read character %d"),
	 charCode);
      pPackedRaster = new BYTE[packetSize];
      inputstream.Read (pPackedRaster, packetSize);
    }
}