Presentation is loading. Please wait.

Presentation is loading. Please wait.

Računarska grafika GDI+ (Graphics Device Interface Plus)

Similar presentations


Presentation on theme: "Računarska grafika GDI+ (Graphics Device Interface Plus)"— Presentation transcript:

1 Računarska grafika GDI+ (Graphics Device Interface Plus)

2 Fonts glyph – an individual mark on a written medium that contributes to the meaning of what is written. font – a complete character set of a single size and style of a particular typeface font family – set of fonts that share the same basicdesign typeface –design of fonts (line width, serif,...) pitch – width of individual characters – fixed pitch – all characters have the same width – variable pitch – some characters are wider and some narrower serif – semi-structural details on the ends of some of the strokes that make up letters and symbols. (sans-serif -> not serif)

3 Font types Bitmap fonts - consist of a matrix of dots or pixels representing the image of each glyph in each face and size. Outline fonts - (also called vector fonts) use Bézier curves, drawing instructions and mathematical formulae to describe each glyph, which make the character outlines scalable to any size. Stroke fonts - use a series of specified lines and additional information to define the profile, or size and shape of the line in a specific face, which together describe the appearance of the glyph.

4 Font formats TrueType – flexible, composed of lines and curves and additional information on each character (. FON and / or. TTF) OpenType – extension of TrueType fonts, so that Adobe PostScript support Compact File Format ClearType – ClearType is a software technology developed by Microsoft that improves the readability of text on existing LCDs

5 Font metric

6 DrawString DrawString(String s, Font font, Brush brush, PointF point) DrawString(String s, Font font, Brush brush, PointF point, StringFormat format) DrawString(String s, Font font, Brush brush, RectangleF layout) s ▫String to draw. font ▫Font that defines the text format of the string. brush ▫Brush that determines the color and texture of the drawn text. point ▫PointF structure that specifies the upper-left corner of the drawn text. format ▫StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text. layout ▫RectangleF structure that specifies the location of the drawn text.

7 DrawString g.DrawString("Računarska grafika, I.Sarajevo", new Font("Arial", 26), new SolidBrush(Color.Blue), new PointF(100, 100));

8 Font Font(String family, Single emSize) Font(String family, Single emSize, FontStyle style) Font(String family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet) family ▫A string representation of the FontFamily for the newFont. emSize ▫The em-size of the new font in the units specified by the unit parameter. style ▫The FontStyle of the new font. unit ▫The GraphicsUnit of the new font. gdiCharSet ▫A Byte that specifies a GDI character set to use for this font.

9 FontStyle NameDescription RegularNormal text. BoldBold text. ItalicItalic text. UnderlineUnderlined text. StrikeoutText with a line through the middle. FontStyle stilic; stilic = FontStyle.Bold | FontStyle.Underline; FontStyle stilic; stilic = FontStyle.Bold | FontStyle.Underline;

10 Font & FontStyle SolidBrush cetkica = new SolidBrush(Color.Blue); FontStyle stilic; stilic = FontStyle.Bold | FontStyle.Underline; Font fontic = new Font("Times New Roman", 26); g.DrawString("Računarska grafika, I.Sarajevo", fontic, cetkica, new PointF(100,100)); fontic = new Font("Times New Roman", 26, stilic); g.DrawString("Računarska grafika, I.Sarajevo", fontic, cetkica, new PointF(100,150));

11 Font & FontStyle

12 StringFormat StringFormat() StringFormat(StringFormatFlags options) ▫Alignment ▫FormatFlags ▫LineAlignment options ▫The StringFormatFlags enumeration for the newStringFormat object.

13 StringFormatFlags Member nameDescription DirectionRightToLeftText is displayed from right to left. DirectionVerticalText is vertically aligned. FitBlackBox Parts of characters are allowed to overhang the string's layout rectangle. By default, characters are repositioned to avoid any overhang. DisplayFormatControlControl characters such as the left-to-right mark are shown in the output with a representative glyph. NoFontFallback Fallback to alternate fonts for characters not supported in the requested font is disabled. Any missing characters are displayed with the fonts missing glyph, usually an open square. MeasureTrailingSpaces Includes the trailing space at the end of each line. By default the boundary rectangle returned by the MeasureString method excludes the space at the end of each line. Set this flag to include that space in measurement.MeasureString NoWrap Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length. LineLimit Only entire lines are laid out in the formatting rectangle. By default layout continues until the end of the text, or until no more lines are visible as a result of clipping, whichever comes first. Note that the default settings allow the last line to be partially obscured by a formatting rectangle that is not a whole multiple of the line height. To ensure that only whole lines are seen, specify this value and be careful to provide a formatting rectangle at least as tall as the height of one line. NoClipOverhanging parts of glyphs, and unwrapped text reaching outside the formatting rectangle are allowed to show. By default all text and glyph parts reaching outside the formatting rectangle are clipped.

14 Font & FontStyle & StringFormat StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.FormatFlags = StringFormatFlags.DirectionVertical; format.LineAlignment = StringAlignment.Far; SolidBrush cetkica = new SolidBrush(Color.Blue); FontStyle stilic; stilic = FontStyle.Bold | FontStyle.Underline; fontic = new Font("Times New Roman", 26, stilic); g.DrawString("Računarska grafika, I.Sarajevo", fontic, cetkica, new PointF(100,150), format);

15 MeasureString MeasureString(String text, Font font) MeasureString(String text, Font font, SizeF layout) MeasureString(String text, Font font, SizeF layout, StringFormat stringFormat) text ▫String to measure. font ▫Font defines the text format of the string. layout ▫SizeF structure that specifies the maximum layout area for the text. stringFormat ▫StringFormat that represents formatting information, such as line spacing, for the string.

16 Example Matrix matricaTransformacija = new Matrix(); matricaTransformacija.Translate(this.ClientRectangle.Wid th/2, this.ClientRectangle.Height/2); g.Transform = matricaTransformacija; Brush cetkica = new SolidBrush(Color.Black); Font fontic = new Font("Arial", 40); float x, y; const int BrojSati = 12; const int StepeniIzmedjuDvaBroja = 360 / BrojSati; const int PoluprecnikSata = 300;

17 Example for (int i = 1; i <= BrojSati; i++) { x = GetCos(i * StepeniIzmedjuDvaBroja + 90) * PoluprecnikSata; y = GetSin(i * StepeniIzmedjuDvaBroja + 90) * PoluprecnikSata; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; g.DrawString(i.ToString(), fontic, cetkica, -x, -y, format); }

18 Example for (int i = 1; i <= BrojSati; i++) { SizeF stringSize = g.MeasureString(i.ToString(), fontic); x = GetCos(i * StepeniIzmedjuDvaBroja + 90) * PoluprecnikSata; x += stringSize.Width / 2; y = GetSin(i * StepeniIzmedjuDvaBroja + 90) * PoluprecnikSata; y += stringSize.Height / 2; g.DrawString(i.ToString(), fontic, cetkica, -x, -y); }

19 Example float GetSin(float UgaoUStep) { return (float)Math.Sin(Math.PI * UgaoUStep / 180f); } float GetCos(float UgaoUStep) { return (float)Math.Cos(Math.PI * UgaoUStep / 180f); }


Download ppt "Računarska grafika GDI+ (Graphics Device Interface Plus)"

Similar presentations


Ads by Google