Exemplo n.º 1
0
    public LegendProperties(Configuration.PrintTemplateContentRow row)
    {
      OriginX = Convert.ToSingle(row.OriginX) * PointsPerInch;
      OriginY = Convert.ToSingle(row.OriginY) * PointsPerInch;
      Width = Convert.ToSingle(row.Width) * PointsPerInch;
      Height = Convert.ToSingle(row.Height) * PointsPerInch;

      string fontFamily = row.IsFontFamilyNull() ? "Helvetica" : row.FontFamily;
      FontSize = row.IsFontSizeNull() ? 12 : Convert.ToSingle(row.FontSize);

      if (!row.IsFontBoldNull() && row.FontBold == 1)
      {
        fontFamily += "-Bold";
      }

      BaseFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

      SwatchHeight = FontSize;
      SwatchWidth = FontSize * 1.4f;
      LayerSpacing = FontSize * 0.5f;
      ClassSpacing = FontSize * 0.15f;
      ColumnSpacing = FontSize * 1.4f;

      ColumnWidth = !row.IsLegendColumnWidthNull() ? Convert.ToSingle(row.LegendColumnWidth) * PointsPerInch :
          FontSize * 12 + SwatchWidth;

      NumColumns = Convert.ToInt32(Math.Floor((Width + ColumnSpacing) / (ColumnWidth + ColumnSpacing)));
    }
Exemplo n.º 2
0
	private void CreatePdfText(PdfContentByte content, Configuration.PrintTemplateContentRow row, string text)
	{
		CreatePdfBox(content, row);

		float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
		float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
		float width = Convert.ToSingle(row.Width) * PointsPerInch;
		float height = Convert.ToSingle(row.Height) * PointsPerInch;

		string fontFamily = "Helvetica";
		int textAlign = PdfContentByte.ALIGN_CENTER;
		float fontSize = 12;
		int textStyle = iTextSharp.text.Font.NORMAL;
		bool textWrap = false;

		int columnAlign = Element.ALIGN_CENTER;

		if (!row.IsTextWrapNull())
		{
			textWrap = row.TextWrap == 1;
		}

		if (!row.IsFontFamilyNull())
		{
			fontFamily = row.FontFamily;
		}

		if (!row.IsFontBoldNull())
		{
			if (row.FontBold == 1)
			{
				if (textWrap)
				{
					textStyle = Font.BOLD;
				}
				else
				{
					fontFamily += "-Bold";
				}
			}
		}

		if (!row.IsFontSizeNull())
		{
			fontSize = Convert.ToSingle(row.FontSize);
		}

		BaseFont baseFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

		if (textWrap)
		{
			if (!row.IsTextAlignNull())
			{
				switch (row.TextAlign)
				{
					case "left":
						columnAlign = Element.ALIGN_LEFT;
						break;
					case "right":
						columnAlign = Element.ALIGN_RIGHT;
						break;
				}
			}

			Font font = new Font(baseFont, fontSize, textStyle);
			content.SetRGBColorFill(0, 0, 0);

			float leading = fontSize * 1.2f;

			ColumnText column = new ColumnText(content);
			column.SetSimpleColumn(originX, originY, originX + width, originY + height, leading, columnAlign);
			column.AddText(new Phrase(leading, text, font));
			column.Go();
		}
		else
		{
			originX += width / 2;

			if (!row.IsTextAlignNull())
			{
				switch (row.TextAlign)
				{
					case "left":
						textAlign = PdfContentByte.ALIGN_LEFT;
						originX -= width / 2;
						break;
					case "right":
						textAlign = PdfContentByte.ALIGN_RIGHT;
						originX += width / 2;
						break;
				}
			}

			content.BeginText();
			content.SetFontAndSize(baseFont, fontSize);
			content.SetRGBColorFill(0, 0, 0);
			content.ShowTextAligned(textAlign, text, originX, originY, 0);
			content.EndText();
		}
	}