Example #1
0
void
VFont::ReadPreamble (/*[in]*/ InputStream & inputStream)
{
  if (inputStream.ReadByte() != id_byte)
    {
      FATAL_DVI_ERROR ("VFont::ReadPreamble",
		       T_("Bad VF file."),
		       dviInfo.fileName.c_str());
    }

  unsigned long commentSize = inputStream.ReadByte();

  char tmp[256];
  inputStream.Read (tmp, commentSize);
  tmp[commentSize] = 0;
  dviInfo.comment = tmp;

  int my_checkSum = inputStream.ReadSignedQuad();
  int my_designSize = inputStream.ReadSignedQuad();

  trace_vfont->WriteFormattedLine
    ("libdvi",
     "comment: %s",
     dviInfo.comment.c_str());
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "checkSum: 0%o",
     my_checkSum);
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "designSize: %d",
     my_designSize);

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

  if (my_checkSum != checkSum)
    {
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%s: checkSum mismatch"),
	 dviInfo.name.c_str());
    }
}
Example #2
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);
    }
}
Example #3
0
void
VFont::ReadFontDef (/*[in]*/ InputStream &	inputStream,
		    /*[in]*/ short		fntDefX)
{
  int fontNum;

  switch (fntDefX)
    {
    case fnt_def1:
      fontNum = inputStream.ReadByte();
      break;
    case fnt_def2:
      fontNum = inputStream.ReadPair();
      break;
    case fnt_def3:
      fontNum = inputStream.ReadTrio();
      break;
    case fnt_def4:
      fontNum = inputStream.ReadSignedQuad();
      break;
    default:
      FATAL_DVI_ERROR ("VFont::ReadFontDef",
		       T_("Bad VF file."),
		       dviInfo.fileName.c_str());
      break;
    }

  trace_vfont->WriteFormattedLine
    ("libdvi",
     T_("defining font %d"),
     fontNum);

  int cs = inputStream.ReadSignedQuad();
  int ss = inputStream.ReadSignedQuad();
  int ds = inputStream.ReadSignedQuad();

  int areaNameSize = inputStream.ReadByte();
  int fontNameSize = inputStream.ReadByte();

  char szArea[256];
  inputStream.Read (szArea, areaNameSize);
  szArea[areaNameSize] = 0;

  char szName[256];
  inputStream.Read (szName, fontNameSize);
  szName[fontNameSize] = 0;

  trace_vfont->WriteFormattedLine
    ("libdvi",
     "areaname: %s",
     szArea);
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "fontname: %s",
     szName);
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "checkSum: 0%o",
     cs);
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "scaledSize: %d",
     ss);
  trace_vfont->WriteFormattedLine
    ("libdvi",
     "designSize: %d",
     ds);
  
  DviFont * pFont;
  PathName fileName;
  if (SessionWrapper(true)->FindFile(szName, FileType::VF, fileName))
    {
      trace_vfont->WriteFormattedLine
	("libdvi",
	 T_("found vf file %s"),
	 Q_(fileName));
      pFont =
	new VFont (pDviImpl,
		   cs,
		   ScaleFix(ss, scaledAt),
		   static_cast<int>(ds * tfmConv),
		   szArea,
		   szName,
		   fileName.Get(),
		   tfmConv,
		   conv,
		   mag,
		   metafontMode.c_str(),
		   baseDpi);
    }
  else if (pDviImpl->GetPageMode() != DviPageMode::Dvips)
    {
      pFont =
	new PkFont (pDviImpl,
		    cs,
		    ScaleFix(ss, scaledAt),
		    static_cast<int>(ds * tfmConv),
		    szArea,
		    szName,
		    "",
		    tfmConv,
		    conv,
		    mag,
		    metafontMode.c_str(),
		    baseDpi);
    }
  else
    {
      pFont =
	new Tfm (pDviImpl,
		 cs,
		 ScaleFix(ss, scaledAt),
		 static_cast<int>(ds * tfmConv),
		 szArea,
		 szName,
		 "",
		 tfmConv,
		 conv);
    }

  fontMap[fontNum] = pFont;
}
Example #4
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);
    }
}