Пример #1
0
		/// <summary>
		/// 20130610 :: Add TextBackground modifiers to paint backgrounds.
		/// 20130718 :: Add arabic support
		/// </summary>
		/// <param name="chunk"></param>
		/// <param name="x"></param>
		/// <param name="width"></param>
		/// <param name="ELEMENT_ALIGN"></param>
		/// <param name="height"></param>
		/// <param name="txtBackgroundAttrs"></param>
		public void DrawBlockString(iTextSharp.text.Chunk chunk, float x, float width, int ELEMENT_ALIGN, float height, BlockStyle txtBackgroundAttrs )
		{
			//20130610 :: mellorasinxelas
			iTextSharp.text.pdf.ColumnText column = new iTextSharp.text.pdf.ColumnText(iPDFContent);
			
			float offsetTextInit = 0.0F;
			if(txtBackgroundAttrs != null && (txtBackgroundAttrs.BackgroundColor != null || txtBackgroundAttrs.BorderColor != null)){
				
				iPDFContent.SaveState();
				
				bool hasBorder = false;
				bool usePath = false;
				bool hasBackground = false;
				
				/*
				public const int TOP_BORDER = 1;
				public const int BOTTOM_BORDER = 2;
				public const int LEFT_BORDER = 4;
				public const int RIGHT_BORDER = 8;
				public const int NO_BORDER = 0;
				 */
				
				//iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle( x, current_y, width, height ); -> no runs
				
				//process border
				if(txtBackgroundAttrs.BorderColor != null && txtBackgroundAttrs.Borders != iTextSharp.text.Rectangle.NO_BORDER){
					iPDFContent.SetColorStroke( new BaseColor( txtBackgroundAttrs.BorderColor.Value ) );
					if(txtBackgroundAttrs.BorderWidth > 0.0F){
						iPDFContent.SetLineWidth( txtBackgroundAttrs.BorderWidth ); //add border width
						//rec.BorderWidth = txtBackgroundAttrs.BorderWidth;	-> no runs
						offsetTextInit = txtBackgroundAttrs.BorderWidth + 1; //add offset.
						hasBorder = true;
					}
					
					//process each border..
					if(txtBackgroundAttrs.Borders != 15){
						usePath = true; //paint border with lines..
					}
				}
				
				//process background
				if(txtBackgroundAttrs.BackgroundColor != null && txtBackgroundAttrs.FillBackground){
					iPDFContent.SetColorFill( new BaseColor( txtBackgroundAttrs.BackgroundColor.Value ) );
					//rec.BackgroundColor = new BaseColor( txtBackgroundAttrs.BackgroundColor.Value ); -> no runs
					hasBackground = true;
				}
				
				//iPDFContent.Rectangle( rec );//draw rectangle -> no runs
				if ((hasBorder && !usePath) || hasBackground){
					//put rectangle
					iPDFContent.Rectangle( x, current_y, width, height );//draw rectangle
				}
				
				if( (hasBorder && !usePath ) && hasBackground){
					iPDFContent.ClosePathFillStroke();
				}
				else if(hasBackground){
					iPDFContent.Fill();
				}
				else if(hasBorder && !usePath){
					iPDFContent.ClosePathStroke();
				}
				else{
					//nothing. If it has border color but hasn't border.
				}
				
				if(usePath){
					//need paint each border
					
					//first top
					if((txtBackgroundAttrs.Borders & iTextSharp.text.Rectangle.TOP_BORDER) == iTextSharp.text.Rectangle.TOP_BORDER ){
						iPDFContent.MoveTo(x, Current_y + height);
						iPDFContent.LineTo( x + width, Current_y + height);
						iPDFContent.Stroke();
					}
					//left
					if((txtBackgroundAttrs.Borders & iTextSharp.text.Rectangle.LEFT_BORDER) == iTextSharp.text.Rectangle.LEFT_BORDER ){
						iPDFContent.MoveTo(x, Current_y);
						iPDFContent.LineTo( x, Current_y + height);
						iPDFContent.Stroke();
					}
					//right
					if((txtBackgroundAttrs.Borders & iTextSharp.text.Rectangle.RIGHT_BORDER) == iTextSharp.text.Rectangle.RIGHT_BORDER ){
						iPDFContent.MoveTo(x + width, Current_y);
						iPDFContent.LineTo( x + width, Current_y + height);
						iPDFContent.Stroke();
					}
					//botton
					if((txtBackgroundAttrs.Borders & iTextSharp.text.Rectangle.BOTTOM_BORDER) == iTextSharp.text.Rectangle.BOTTOM_BORDER ){
						iPDFContent.MoveTo(x, Current_y);
						iPDFContent.LineTo( x + width, Current_y);
						iPDFContent.Stroke();
					}
				}
				
				iPDFContent.RestoreState();
			}
			//----
			
			//paint text column. Add offset
			column.SetSimpleColumn( x + offsetTextInit			, current_y ,
			                       x + width - offsetTextInit	, current_y + height
			                      );//add offset
			column.AddText(chunk);
			column.Alignment = ELEMENT_ALIGN;
			column.SetLeading(0, 1);
			
			//20130718 :: Add arabic support
			if (_detectRightToLeft && IsArabicHebrewText(chunk.Content))
			{
				column.RunDirection = iTextSharp.text.pdf.PdfWriter.RUN_DIRECTION_RTL;
			}
			//----
			
			column.Go();
		}
Пример #2
0
		/// <summary>
		/// Draws a block string
		/// </summary>
		/// <param name="txt"></param>
		/// <param name="x"></param>
		/// <param name="width"></param>
		/// <param name="fontAttrs"></param>
		/// <param name="textAttrs"></param>
		public void DrawBlockString(string txt, float x, float width,
		                            XmlAttributeCollection fontAttrs, XmlAttributeCollection textAttrs)
		{
			iTextSharp.text.Font font = CreateFontFromAttribute(fontAttrs);
			int align = PDFDrawItextSharpHelper.Align(
				Moon.PDFDraw.Helper.GetAttributeValue(AlignAttributeConstant, textAttrs, "Near"));
			
			iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(txt, font);
			
			//20130605 :: mellorasinxelas
			BlockStyle backgroundDef = new BlockStyle( textAttrs );//load text background values.
			
			if(backgroundDef.BackgroundColor != null){
				chunk.SetBackground( new BaseColor(backgroundDef.BackgroundColor.Value) );//sets the same backcolor to the text.
			}
			//----
			float height = Moon.PDFDraw.Helper.GetFloatAttributeValue( "height", textAttrs, font.Size + (font.Size / 2));

			DrawBlockString(chunk, x, width, align, height, backgroundDef);
		}