本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.GetEffectiveStringWidth方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.GetEffectiveStringWidth方法的具體用法?C# PdfContentByte.GetEffectiveStringWidth怎麽用?C# PdfContentByte.GetEffectiveStringWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.GetEffectiveStringWidth方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateLayerInLegend
private bool CreateLayerInLegend(PdfContentByte content, Configuration.MapTabRow mapTab, List<CommonLayer> layerList, LegendProperties properties, CommonLayer layer, float indent)
{
if (!layerList.Contains(layer))
{
return false;
}
float layerHeight = GetLayerHeightInLegend(layerList, properties, layer);
if (properties.CurrentY < properties.Height && properties.CurrentY - layerHeight < 0)
{
if (properties.CurrentColumn == properties.NumColumns)
{
return true;
}
properties.CurrentX += properties.ColumnWidth + properties.ColumnSpacing;
properties.CurrentY = properties.Height;
properties.CurrentColumn += 1;
}
int numClasses = GetNumClasses(layer);
Configuration.LayerRow configLayer = mapTab.GetMapTabLayerRows().Where(o => String.Compare(o.LayerRow.LayerName, layer.Name, true) == 0).Select(o => o.LayerRow).FirstOrDefault();
string layerName = configLayer != null && !configLayer.IsDisplayNameNull() ? configLayer.DisplayName : layer.Name;
// write the layer name
if (layer.Type == CommonLayerType.Group || numClasses > 1)
{
properties.CurrentY -= properties.FontSize;
string name = layerName;
try
{
while (content.GetEffectiveStringWidth(name, false) > properties.ColumnWidth - indent)
{
name = name.Substring(0, name.Length - 1);
}
}
catch { }
content.BeginText();
content.SetFontAndSize(properties.BaseFont, properties.FontSize);
content.SetRGBColorFill(0, 0, 0);
content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, name, properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
content.EndText();
}
if (layer.Type == CommonLayerType.Group)
{
properties.CurrentY -= properties.LayerSpacing;
foreach (CommonLayer childLayer in layer.Children)
{
CreateLayerInLegend(content, mapTab, layerList, properties, childLayer, indent + 1.5f * properties.FontSize);
}
}
else
{
properties.CurrentY -= properties.ClassSpacing;
foreach (CommonLegendGroup legendGroup in layer.Legend.Groups)
{
foreach (CommonLegendClass legendClass in legendGroup.Classes)
{
if (!legendClass.ImageIsTransparent)
{
properties.CurrentY -= properties.SwatchHeight;
MemoryStream stream = new MemoryStream(legendClass.Image);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
float w = properties.SwatchHeight * bitmap.Width / bitmap.Height;
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(legendClass.Image);
image.SetAbsolutePosition(properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY - properties.SwatchHeight * 0.1f);
image.ScaleAbsolute(w, properties.SwatchHeight);
content.AddImage(image);
string label = numClasses > 1 ? legendClass.Label : layerName;
try
{
while (content.GetEffectiveStringWidth(label, false) > properties.ColumnWidth - properties.SwatchWidth - properties.ClassSpacing)
{
label = label.Substring(0, label.Length - 1);
}
}
catch { }
content.BeginText();
content.SetFontAndSize(properties.BaseFont, properties.FontSize);
content.SetRGBColorFill(0, 0, 0);
content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, label, properties.OriginX + properties.CurrentX + indent + properties.SwatchWidth + properties.ClassSpacing, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
content.EndText();
properties.CurrentY -= properties.ClassSpacing;
}
}
}
//.........這裏部分代碼省略.........
示例2: Draw
public void Draw(PdfContentByte cb, IList<float[]> lines, IList<IElement> list)
{
if (lines.Count < 2)
{
return; //Do nothing
}
//TODO check all the style elements
cb.SetLineWidth(3);
//first set a letter type
BaseFont bf = BaseFont.CreateFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
cb.SetFontAndSize(bf, fontsize);
float xPrevious = lines[0][0], yPrevious = lines[0][1];
int indexOfTextElement = 0, indexOfCharacter = 0;
String currentCharacter = GetCharacter(indexOfTextElement, indexOfCharacter);
while (string.IsNullOrEmpty(currentCharacter))
{
if (indexOfCharacter >= GetLengthOfText(indexOfTextElement) - 1)
{
//this was the last character of the text element
if (indexOfTextElement == list.Count - 1)
{
//this was the last text element; exit while loop
return; //stop
}
else
{
//goto first character of the next element
//TODO set the css
indexOfTextElement++;
indexOfCharacter = 0;
}
}
currentCharacter = GetCharacter(indexOfTextElement, indexOfCharacter);
}
double halfWidthOfCharacter = cb.GetEffectiveStringWidth(currentCharacter, true)/2.0;
double totalLength = 0;
bool lookForStart = true;
for (int j = 1; j < lines.Count; j++)
{
float[] point = lines[j];
double lengthLijnStuk = CalculateDistance(xPrevious, yPrevious, point[0], point[1]);
//System.out.Println(lengthLijnStuk);
totalLength = totalLength + lengthLijnStuk;
//System.out.Println(totalLength);
while (totalLength >= halfWidthOfCharacter)
{
double tussen = totalLength - halfWidthOfCharacter;
double xyAlongThis = lengthLijnStuk - tussen - halfWidthOfCharacter;
double[] xy = GetPointOnLine(xPrevious, yPrevious, point[0], point[1], xyAlongThis);
if (lookForStart)
{
ShowText(cb, point[0], point[1], xPrevious, yPrevious, xy[0], xy[1], currentCharacter);
lookForStart = false;
totalLength = tussen; //distance to the end of the line segment
}
else
{
//look for the end point
lookForStart = true;
totalLength = tussen; //distance to the end of the line segment
indexOfCharacter++;
currentCharacter = GetCharacter(indexOfTextElement, indexOfCharacter);
while (currentCharacter == null || currentCharacter.Length == 0)
{
if (indexOfCharacter >= GetLengthOfText(indexOfTextElement) - 1)
{
//this was the last character of the text element
if (indexOfTextElement == list.Count - 1)
{
//this was the last text element; exit while loop
return;
}
else
{
//goto first character of the next element
indexOfTextElement++;
indexOfCharacter = 0;
}
}
currentCharacter = GetCharacter(indexOfTextElement, indexOfCharacter);
}
halfWidthOfCharacter = cb.GetEffectiveStringWidth(currentCharacter, true)/2.0;
}
}
xPrevious = point[0];
yPrevious = point[1];
//.........這裏部分代碼省略.........
示例3: DrawBox
void DrawBox(
Document doc,
PdfContentByte cb,
Certificate c,
CertificateArea box,
string text,
bool wrap)
{
if (null == box || !box.Enabled || String.IsNullOrEmpty(text))
{
return;
}
var origin = (float)box.Left;
var alignment = PdfContentByte.ALIGN_LEFT;
switch (box.Alignment)
{
case "center":
alignment = PdfContentByte.ALIGN_CENTER;
origin = (box.Left + box.Width/2);
break;
case "right":
alignment = PdfContentByte.ALIGN_RIGHT;
origin = box.Left + box.Width;
break;
}
var size = 0 == box.FontSize ? 12f : box.FontSize;
cb.SetFontAndSize(
BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false),
size);
cb.BeginText();
if (wrap)
{
var y = 0;
var line = 0;
for (var x = 0; x < text.Length; x++)
{
var sub = text.Substring(y, x - y);
var width = cb.GetEffectiveStringWidth(sub, false);
if (width >= 10f * Dpi * box.Width / c.BackgroundSize.Width)
{
// backup to the last whitespace char
while (x > y && Char.IsLetterOrDigit(text[x]))
{
x--;
}
sub = text.Substring(y, x - y);
cb.ShowTextAligned(
alignment,
sub,
(0.5f*Dpi) + (10f*Dpi*origin/c.BackgroundSize.Width),
(0.5f*Dpi) + (7.5f*Dpi) - (7.5f*Dpi*box.Top/c.BackgroundSize.Height) - size - (line * size),
0f
);
y = x;
line++;
}
}
}
else
{
cb.ShowTextAligned(
alignment,
text,
(0.5f * Dpi) + (10f * Dpi * origin / c.BackgroundSize.Width),
(0.5f * Dpi) + (7.5f * Dpi) - (7.5f * Dpi * box.Top / c.BackgroundSize.Height) - size,
0f
);
}
cb.EndText();
}