C# 클래스 PDFExport.PDFGraphics

Implements the IGraphics interface for the PDF-Sharp output.
Every point, path, rectangle and so on is measured in pixels. PDF doesn't know about pixels, but dots. One dot is the 72th of an inch. So one has to apply some scaling for alle drawn elements. This can be done with a call to ScaleTransform for example to get from pixel coordinates to dot coordinates. This solution has one disadvantage: There are a few points where PDF-Sharp scales from pixels to dots itself: fonts and images. If we don't care about this, all fonts and images would appear to small in the resulting PDF. The solution is to "unscale" those elements first. To do this, there are the two properties ScaleFont and ScaleImage. //We take the DPI of the screen from a Control Graphics gdiGraphics = (new Control()).CreateGraphics(); //Apply a scaling to get from pixels to dots graphics.ScaleTransform(72.0f / gdiGraphics.DpiX, 72.0f / gdiGraphics.DpiY); //Unscale the font graphics.ScaleFont = gdiGraphics.DpiY / 72.0f; //Unscale the images graphics.ScaleImage = gdiGraphics.DpiX / 72.0f; graphics.TakeInitialTransform(); Word wrap is slightly different to the GDI word wrapping. If a single word is longer than a line, GDI breaks the word and prints the rest in a new line. Here the rest isn't printed but an ellipsis is appendet to the not fitting word. The following points are on the to do list: - Clipping isn't very good right now. We should unerstand the regions. There are a few things which are not perfect and won't be changed now: - Only horizontal, vertical and diagonal gradients are drawn correctly. Thats ok since NClass dosn't use any other gradients. - Images get a gray border in pdf if they have colored (even white) pixels next to transparent pixels. A workaround is to draw them by GDI on a surface. This surface is white. This looks good until the backgound of the entity is also white. If not, images are inside a white box. - If one draws with a gradient brush and the next drawing operation uses a black brush, this drawing is done with the gradient again. That's because the brush isn't changed in pdf. This is a bug in PDFSharp.
상속: IGraphics
파일 보기 프로젝트 열기: gbaychev/NClass 1 사용 예제들

공개 메소드들

메소드 설명
DrawEllipse ( Pen pen, int x, int y, int width, int height ) : void
DrawImage ( Image image, Point point ) : void
DrawImage ( Image image, int x, int y ) : void
DrawLine ( Pen pen, Point pt1, Point pt2 ) : void
DrawLine ( Pen pen, int x1, int y1, int x2, int y2 ) : void
DrawLines ( Pen pen, Point points ) : void
DrawPath ( Pen pen, GraphicsPath path ) : void
DrawPolygon ( Pen pen, Point points ) : void
DrawRectangle ( Pen pen, Rectangle rect ) : void
DrawString ( string s, Font font, Brush brush, PointF point ) : void
DrawString ( string s, Font font, Brush brush, PointF point, StringFormat format ) : void
DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle ) : void
DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format ) : void
FillEllipse ( Brush brush, Rectangle rect ) : void
FillEllipse ( Brush brush, int x, int y, int width, int height ) : void
FillPath ( Brush brush, GraphicsPath path ) : void
FillPolygon ( Brush brush, Point points ) : void
FillRectangle ( Brush brush, Rectangle rect ) : void
PDFGraphics ( XGraphics graphics ) : System

Initializes a new instnace of PDFGraphics.

ResetTransform ( ) : void
RotateTransform ( float angle ) : void
ScaleTransform ( float sx, float sy ) : void
SetClip ( GraphicsPath path, CombineMode combineMode ) : void
SetClip ( Rectangle rect, CombineMode combineMode ) : void
SetClip ( RectangleF rect, CombineMode combineMode ) : void
SetClip ( Region region, CombineMode combineMode ) : void
TakeInitialTransform ( ) : void

Takes the inital state.

TranslateTransform ( float dx, float dy ) : void

비공개 메소드들

메소드 설명
ApplyClip ( Region region ) : void

Applies the clipping stored in region.

BrushToXBrush ( Brush brush ) : PdfSharp.Drawing.XBrush

Converts a GDI-Brush to a PDF-XBrush.

Only Solid- and LinearGradientBrushes are supported.

CombineClippingRegion ( CombineMode combineMode, Region region ) : void

Combines the local clippingRegion with the given region.

DashStyleToXDashStyle ( DashStyle dashStyle ) : XDashStyle

Converts a GDI-DashStyle to a PDF-XDashStyle.

FillModeToXFillMode ( FillMode fillMode ) : XFillMode

Converts a GDI-FillMode to a PDF-XFillMode.

FloatArrayToDoubleArray ( float floats ) : double[]

Converts an array of floats to an array of doubles.

FontStyleToXFontStyle ( FontStyle fontStyle ) : XFontStyle

Converts a GDI-FontStyle to a PDF-XFontStyle.

FontToXFont ( Font font ) : PdfSharp.Drawing.XFont

Converts a GDI-Font to a PDF-XFont.

GraphicsPathToXGraphicsPath ( GraphicsPath path ) : PdfSharp.Drawing.XGraphicsPath

Converts a GDI-GraphicsPath to a PDF-XGraphicsPath.

ImageToXImage ( Image image ) : PdfSharp.Drawing.XImage

Converts a GDI-Image to a PDF-XImage.

The GDI-Image gets drawn on a white background.

LineCapToXLineCap ( LineCap lineCap ) : XLineCap

Converts a GDI-LineCap to a PDF-XLineCap.

PDF only supports square, round and flat line caps. So all the other GDI line caps gets mapped to the best PDF line caps as follows. XLineCap.Square LineCap.Square LineCap.Triangle LineCap.SquareAnchor LineCap.DiamondAnchor LineCap.ArrowAnchor XLineCap.Round LineCap.Round LineCap.RoundAnchor XLineCap.Flat LineCap.Flat LineCap.NoAnchor LineCap.Custom LineCap.AnchorMask

LineJoinToXLineJoin ( LineJoin lineJoin ) : XLineJoin

Converts a GDI-LineJoin to a PDF-XLineJoin.

PDF doesn't support LineJoin.MiterClipped so this is mapped to XLineJoin.Miter, too.

PenToXPen ( Pen pen ) : PdfSharp.Drawing.XPen

Converts a GDI-Pen to a PDF-XPen.

RestoreInitialClip ( ) : void

Resets the clipping.

RestoreInitialTransform ( ) : void

Restores the state to the initial state.

SetText ( String text, float width, int maxLines, PdfSharp.Drawing.XFont xFont ) : List

This method will take a text and do a word wrap so it fits into the given width. If a line is wider than width, a new line is started. If the resulting line count is greater than maxLines, an ellipsis is added. The result is a list of strings where one item per line.

StringAlignmentToXLineAlignment ( StringAlignment stringAlignment ) : XLineAlignment

Converts a GDI-StringAlignment to a PDF-XLineAlignment.

StringAlignmentToXStringAlignment ( StringAlignment stringAlignment ) : XStringAlignment

Converts a GDI-StringAlignment to a PDF-XStringAlignment.

StringFormatFlagsToXStringFormatFlags ( StringFormatFlags stringFormatFlags ) : XStringFormatFlags

Converts a GDI-StringFormatFlags to a PDF-XStringFormatFlags.

StringFormatToXStringFormat ( StringFormat format ) : PdfSharp.Drawing.XStringFormat

Converts a GDI-StringFormat to a PDF-XStringFormat.

TokenizeString ( string text, string separator ) : List

This method will devide string by a separator and return the tokens as a list. The list will contain the text between the separators as well as the separators itself.

TrimString ( string s, float width, PdfSharp.Drawing.XFont font, StringTrimming stringTrimming ) : string

Trims a string so it fits into the rectangle. Only one line is trimed.

The StringTrimming.EllipsisPath is handeled as StringTrimming.EllipsisCharacter.

메소드 상세

DrawEllipse() 공개 메소드

public DrawEllipse ( Pen pen, int x, int y, int width, int height ) : void
pen System.Drawing.Pen
x int
y int
width int
height int
리턴 void

DrawImage() 공개 메소드

public DrawImage ( Image image, Point point ) : void
image Image
point Point
리턴 void

DrawImage() 공개 메소드

public DrawImage ( Image image, int x, int y ) : void
image Image
x int
y int
리턴 void

DrawLine() 공개 메소드

public DrawLine ( Pen pen, Point pt1, Point pt2 ) : void
pen System.Drawing.Pen
pt1 Point
pt2 Point
리턴 void

DrawLine() 공개 메소드

public DrawLine ( Pen pen, int x1, int y1, int x2, int y2 ) : void
pen System.Drawing.Pen
x1 int
y1 int
x2 int
y2 int
리턴 void

DrawLines() 공개 메소드

public DrawLines ( Pen pen, Point points ) : void
pen System.Drawing.Pen
points Point
리턴 void

DrawPath() 공개 메소드

public DrawPath ( Pen pen, GraphicsPath path ) : void
pen System.Drawing.Pen
path System.Drawing.Drawing2D.GraphicsPath
리턴 void

DrawPolygon() 공개 메소드

public DrawPolygon ( Pen pen, Point points ) : void
pen System.Drawing.Pen
points Point
리턴 void

DrawRectangle() 공개 메소드

public DrawRectangle ( Pen pen, Rectangle rect ) : void
pen System.Drawing.Pen
rect System.Drawing.Rectangle
리턴 void

DrawString() 공개 메소드

public DrawString ( string s, Font font, Brush brush, PointF point ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
point System.Drawing.PointF
리턴 void

DrawString() 공개 메소드

public DrawString ( string s, Font font, Brush brush, PointF point, StringFormat format ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
point System.Drawing.PointF
format System.Drawing.StringFormat
리턴 void

DrawString() 공개 메소드

public DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
layoutRectangle System.Drawing.RectangleF
리턴 void

DrawString() 공개 메소드

public DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
layoutRectangle System.Drawing.RectangleF
format System.Drawing.StringFormat
리턴 void

FillEllipse() 공개 메소드

public FillEllipse ( Brush brush, Rectangle rect ) : void
brush System.Drawing.Brush
rect System.Drawing.Rectangle
리턴 void

FillEllipse() 공개 메소드

public FillEllipse ( Brush brush, int x, int y, int width, int height ) : void
brush System.Drawing.Brush
x int
y int
width int
height int
리턴 void

FillPath() 공개 메소드

public FillPath ( Brush brush, GraphicsPath path ) : void
brush System.Drawing.Brush
path System.Drawing.Drawing2D.GraphicsPath
리턴 void

FillPolygon() 공개 메소드

public FillPolygon ( Brush brush, Point points ) : void
brush System.Drawing.Brush
points Point
리턴 void

FillRectangle() 공개 메소드

public FillRectangle ( Brush brush, Rectangle rect ) : void
brush System.Drawing.Brush
rect System.Drawing.Rectangle
리턴 void

PDFGraphics() 공개 메소드

Initializes a new instnace of PDFGraphics.
public PDFGraphics ( XGraphics graphics ) : System
graphics PdfSharp.Drawing.XGraphics An instance of which is used to /// create the PDF.
리턴 System

ResetTransform() 공개 메소드

public ResetTransform ( ) : void
리턴 void

RotateTransform() 공개 메소드

public RotateTransform ( float angle ) : void
angle float
리턴 void

ScaleTransform() 공개 메소드

public ScaleTransform ( float sx, float sy ) : void
sx float
sy float
리턴 void

SetClip() 공개 메소드

public SetClip ( GraphicsPath path, CombineMode combineMode ) : void
path System.Drawing.Drawing2D.GraphicsPath
combineMode CombineMode
리턴 void

SetClip() 공개 메소드

public SetClip ( Rectangle rect, CombineMode combineMode ) : void
rect System.Drawing.Rectangle
combineMode CombineMode
리턴 void

SetClip() 공개 메소드

public SetClip ( RectangleF rect, CombineMode combineMode ) : void
rect System.Drawing.RectangleF
combineMode CombineMode
리턴 void

SetClip() 공개 메소드

public SetClip ( Region region, CombineMode combineMode ) : void
region System.Drawing.Region
combineMode CombineMode
리턴 void

TakeInitialTransform() 공개 메소드

Takes the inital state.
public TakeInitialTransform ( ) : void
리턴 void

TranslateTransform() 공개 메소드

public TranslateTransform ( float dx, float dy ) : void
dx float
dy float
리턴 void