private void WriteGlyphs(Glyphs glyphs)
{
WriteSaveState("begin Glyphs", glyphs.Name);
// Transform also affects clipping and opacity mask
bool transformed = glyphs.RenderTransform != null;
if (transformed)
WriteRenderTransform(glyphs.RenderTransform);
bool clipped = glyphs.Clip != null;
if (clipped)
WriteClip(glyphs.Clip);
if (glyphs.Opacity < 1)
MultiplyOpacity(glyphs.Opacity);
if (glyphs.OpacityMask != null)
WriteOpacityMask(glyphs.OpacityMask);
XForm xform = null;
XImage ximage = null;
RealizeFill(glyphs.Fill, ref xform, ref ximage);
RealizeFont(glyphs);
double x = glyphs.OriginX;
double y = glyphs.OriginY;
//switch (format.Alignment)
//{
// case XStringAlignment.Near:
// // nothing to do
// break;
// case XStringAlignment.Center:
// x += (rect.Width - width) / 2;
// break;
// case XStringAlignment.Far:
// x += rect.Width - width;
// break;
//}
PdfFont realizedFont = this.graphicsState.realizedFont;
Debug.Assert(realizedFont != null);
realizedFont.AddChars(glyphs.UnicodeString);
TrueTypeDescriptor descriptor = realizedFont.FontDescriptor.descriptor;
//if (bold && !descriptor.IsBoldFace)
//{
// // TODO: emulate bold by thicker outline
//}
//if (italic && !descriptor.IsBoldFace)
//{
// // TODO: emulate italic by shearing transformation
//}
string s2 = "";
string s = glyphs.UnicodeString;
if (!String.IsNullOrEmpty(s))
{
int length = s.Length;
for (int idx = 0; idx < length; idx++)
{
char ch = s[idx];
int glyphID = 0;
if (descriptor.fontData.cmap.symbol)
{
glyphID = (int)ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00);
glyphID = descriptor.CharCodeToGlyphIndex((char)glyphID);
}
else
glyphID = descriptor.CharCodeToGlyphIndex(ch);
s2 += (char)glyphID;
}
}
s = s2;
byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s);
bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null);
string text = PdfEncoders.RawEncoding.GetString(bytes);
if (glyphs.IsSideways)
{
XMatrix textMatrix = new XMatrix();
textMatrix.RotateAtPrepend(-90, new XPoint(x, y));
XPoint pos = new XPoint(x, y);
AdjustTextMatrix(ref pos);
WriteTextTransform(textMatrix);
WriteLiteral("{0} Tj\n", text);
}
else
{
XPoint pos = new XPoint(x, y);
AdjustTextMatrix(ref pos);
WriteLiteral("{0:0.###} {1:0.###} Td {2} Tj\n", pos.x, pos.y, text);
//PdfEncoders.ToStringLiteral(s, PdfStringEncoding.RawEncoding, null));
}
WriteRestoreState("end Glyphs", glyphs.Name);
}