CS-460/560, Wk-5A Spring, 1998 R. Eckert TEXT-- Two general techniques used-- Bitmapped--Each character is represented (stored) as a 2-D array. Each element corresponds to a pixel in a rectangular character cell. Simplest: each element is a bit (1=pixel on, 0=pixel off). Stroked--Each character is represented (stored) as a series of line segments (or sometimes as more complex primitives such as arcs). Parameters needed to draw the stroke (endpoint coordinates in the case of line segments) are stored. Characteristics of Bitmapped characters-- Each character in the set requires same amount of memory to store. Characters can only be scaled by integer scaling factors --> "Blocky" appearance. Difficult to rotate characters by arbitrary angles. Characteristics of Stroked characters-- Number of stokes (storage space) depents on complexity of character. Each stroke must be scan converted ==> more time to display. Can be easily scaled and rotated by arbitrary amounts--just transform each stroke. CHARACTER FONTS IN WINDOWS-- FONT--Typeface, style, size of characters in a character set. Three kinds of fonts-- Stock fonts--built into Windows, always available: (ANSI_FIXED_FONT, ANSI_VAR_FONT, DEVICE_DEFAULT_FONT, OEM_FIXED_FONT, SYSTEM_FONT, SYSTEM_FIXED_FONT) Logical or GDI fonts--defined in separate .fon (stroke or raster) or .fot/.ttf (TrueType--"rasterized stroke") font resource files stored on disk. Device fonts--native to the output device (e.g., built-in printer fonts). Using stock fonts-- Like stock pens, brushes; accessed w/ GetStockObject() -- returns a handle to a font that can be used by SelectObject(): HDC hDC; HFONT hFont; hDC = GetDC(hWnd); hFont = GetStockObject (ANSI_VAR_FONT); SelectObject (hDC,hFont); /* now can use it */ Using Logical Fonts-- To use font data in a pgm-- -Obtain a handle to the font data resource and select it into the DC-- -Just like stock font, except loaded from separate file (.fon, .fot/.ttf) -Use CreateFont() instead of GetStockObject() to load & get font handle -CreateFont() can make new fonts by interpolating data in a font file ==> new sizes, bold/underlined, rotated/distorted characters -Called logical since they come from pgm logic not just from a file hFont = CreateFont(Ht, Width, Escapement, Orientation, Weight, Italic, Underline, StrikeOut, CharSet, OutputPrecision, ClipPrecision, Quality, PitchAndFamily, Facename) 14 parameters, many often set to 0 ==> defaults (on-line help on CreateFont): Heights and Widths--measured in logical units. With default units of a DC; these are equal to pixels. Escapement--Specifies the angle, in tenths of degrees, between the line through the origins of the first and last characters on a line and the x-axis of the screen surface. Orientation--how much char should be rotated in tenths of degree (900 ==> char lying on its back). Weight--How thickly to print char lines (FW_NORMAL=400, FW_BOLD=700, others) Italic--TRUE/FALSE Underline--TRUE/FALSE StrikeOut--TRUE/FALSE --> chars /w line thru center CharSet--ANSI_CHARSET, SYMBOL_CHARSET, OEM_CHARSET, SHIFTJIS_CHARSET OutputPrecision--How closely output must match requested font ht/width/ orientation/escapement/pitch; several possibilities. ClipPrecision--How to clip characters partially outside clipping region. Quality-- DRAFT_QUALITY, PROOF_QUALITY , DEFAULT_QUALITY (most common) PitchAndFamily--2 values "OR'd": -First (low order 2 bits):-->font pitch (DEFAULT_PITCH, FIXED_PITCH, VARIABLE_PITCH); -Second (high order 4 bits): --> font family (FF_DECORATIVE, FF_DONTCARE, FF_MODERN, FF_ROMAN, FF_SCRIPT, FF_SWISS) -e.g., DEFAULT_PITCH | FF_ROMAN Facename--ptr to string that specifies typeface name (style) of font data; identifies font resource data file, e.g.: Courier, MS Serif, MS Sans Serif, Symbol Small Fonts, Modern, Roman, Script; Courier New, Courier New Bold, Courier New Italic Courier New Bold.... TEXT METRICS-- CreateFont() may not give you exactly what you ask for; you may not know all of the dimensions of a font after its created. So use GetTextMetrics() to find out font details --> lots of info in a TEXTMETRIC structure <search on TEXTMETRIC> . Commonly used to determine font size which can be used to set line spacing, caret size, sizes of buttons, etc.