本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.SetWordSpacing方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.SetWordSpacing方法的具體用法?C# PdfContentByte.SetWordSpacing怎麽用?C# PdfContentByte.SetWordSpacing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.SetWordSpacing方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteTextChunks
/**
* Writes parts of text which are visible into a content stream.
*/
private void WriteTextChunks(IDictionary<int, float> structuredTJoperands, IList<PdfCleanUpContentChunk> chunks, PdfContentByte canvas,
float characterSpacing, float wordSpacing, float fontSize, float horizontalScaling) {
canvas.SetCharacterSpacing(0);
canvas.SetWordSpacing(0);
canvas.InternalBuffer.Append((byte) '[');
float convertedCharacterSpacing = -characterSpacing * 1000f / fontSize;
float convertedWordSpacing = -wordSpacing * 1000f / fontSize;
float shift = structuredTJoperands != null ? structuredTJoperands[0] : 0;
PdfCleanUpContentChunk.Text prevChunk = null;
foreach (PdfCleanUpContentChunk chunk in chunks) {
PdfCleanUpContentChunk.Text textChunk = (PdfCleanUpContentChunk.Text) chunk;
if (prevChunk != null && prevChunk.NumOfStrTextBelongsTo != textChunk.NumOfStrTextBelongsTo &&
structuredTJoperands != null) {
shift += structuredTJoperands[prevChunk.NumOfStrTextBelongsTo];
}
if (textChunk.Visible) {
if (Util.compare(shift, 0.0f) != 0 && Util.compare(shift, -0.0f) != 0) {
canvas.InternalBuffer.Append(shift).Append(' ');
}
textChunk.GetText().ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
canvas.InternalBuffer.Append(' ');
shift = convertedCharacterSpacing + (IsSpace(textChunk) ? convertedWordSpacing : 0);
} else {
shift += GetUnscaledTextChunkWidth(textChunk, characterSpacing, wordSpacing,
fontSize, horizontalScaling);
}
prevChunk = textChunk;
}
if (Util.compare(shift, 0) != 0 && Util.compare(shift, -0.0f) != 0) {
canvas.InternalBuffer.Append(shift);
}
canvas.InternalBuffer.Append(TJ);
if (Util.compare(characterSpacing, 0) != 0 && Util.compare(characterSpacing, -0.0f) != 0) {
new PdfNumber(characterSpacing).ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
canvas.InternalBuffer.Append(Tc);
}
if (Util.compare(wordSpacing, 0) != 0 && Util.compare(wordSpacing, -0.0f) != 0) {
new PdfNumber(wordSpacing).ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
canvas.InternalBuffer.Append(Tw);
}
}
示例2: WriteLineToContent
//.........這裏部分代碼省略.........
subtract += hangingCorrection;
Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
IPdfPageEvent pev = writer.PageEvent;
if (pev != null)
pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
}
if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
float subtract = lastBaseFactor;
if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
subtract = 0;
if (nextChunk == null)
subtract += hangingCorrection;
PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
text.AddAnnotation(annot, true);
}
float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
object hs = chunk.GetAttribute(Chunk.HSCALE);
if (paramsx != null || hs != null) {
float b = 0, c = 0;
if (paramsx != null) {
b = paramsx[0];
c = paramsx[1];
}
if (hs != null)
hScale = (float)hs;
text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
}
if (!isJustified)
{
if (chunk.IsAttribute(Chunk.WORD_SPACING))
{
float ws = (float)chunk.GetAttribute(Chunk.WORD_SPACING);
text.SetWordSpacing(ws);
}
}
if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
float cs = (float) chunk.GetAttribute(Chunk.CHAR_SPACING);
text.SetCharacterSpacing(cs);
}
if (chunk.IsImage()) {
Image image = chunk.Image;
width = chunk.ImageWidth;
float[] matrix = image.GetMatrix(chunk.ImageScalePercentage);
matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
text.MoveText(xMarker + lastBaseFactor + chunk.ImageWidth - text.XTLM, 0);
}
}
xMarker += width;
++chunkStrokeIdx;
}
if (!chunk.IsImage() && chunk.Font.CompareTo(currentFont) != 0) {
currentFont = chunk.Font;
text.SetFontAndSize(currentFont.Font, currentFont.Size);
}
float rise = 0;
Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
int tr = 0;
float strokeWidth = 1;
BaseColor strokeColor = null;
object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
示例3: WriteLineToContent
//.........這裏部分代碼省略.........
}
xMarker += width;
++chunkStrokeIdx;
}
if (chunk.Font.CompareTo(currentFont) != 0) {
currentFont = chunk.Font;
text.SetFontAndSize(currentFont.Font, currentFont.Size);
}
float rise = 0;
Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
int tr = 0;
float strokeWidth = 1;
Color strokeColor = null;
object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
if (textRender != null) {
tr = (int)textRender[0] & 3;
if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
text.SetTextRenderingMode(tr);
if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
strokeWidth = (float)textRender[1];
if (strokeWidth != 1)
text.SetLineWidth(strokeWidth);
strokeColor = (Color)textRender[2];
if (strokeColor == null)
strokeColor = color;
if (strokeColor != null)
text.SetColorStroke(strokeColor);
}
}
if (fr != null)
rise = (float)fr;
if (color != null)
text.SetColorFill(color);
if (rise != 0)
text.SetTextRise(rise);
if (chunk.IsImage()) {
adjustMatrix = true;
}
// If it is a CJK chunk or Unicode TTF we will have to simulate the
// space adjustment.
else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
if (hScale != lastHScale) {
lastHScale = hScale;
text.SetWordSpacing(baseWordSpacing / hScale);
text.SetCharacterSpacing(baseCharacterSpacing / hScale);
}
String s = chunk.ToString();
int idx = s.IndexOf(' ');
if (idx < 0)
text.ShowText(chunk.ToString());
else {
float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
int lastIdx = idx;
while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
textArray.Add(spaceCorrection);
textArray.Add(s.Substring(lastIdx, idx - lastIdx));
lastIdx = idx;
}
textArray.Add(spaceCorrection);
textArray.Add(s.Substring(lastIdx));
text.ShowText(textArray);
}
}
else {
if (isJustified && hScale != lastHScale) {
lastHScale = hScale;
text.SetWordSpacing(baseWordSpacing / hScale);
text.SetCharacterSpacing(baseCharacterSpacing / hScale);
}
text.ShowText(chunk.ToString());
}
if (rise != 0)
text.SetTextRise(0);
if (color != null)
text.ResetRGBColorFill();
if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
if (strokeColor != null)
text.ResetRGBColorStroke();
if (strokeWidth != 1)
text.SetLineWidth(1);
if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
adjustMatrix = true;
text.SetTextMatrix(xMarker, yMarker);
}
}
if (isJustified) {
text.SetWordSpacing(0);
text.SetCharacterSpacing(0);
if (line.NewlineSplit)
lastBaseFactor = 0;
}
if (adjustMatrix)
text.MoveText(baseXMarker - text.XTLM, 0);
currentValues[0] = currentFont;
currentValues[1] = lastBaseFactor;
}