UFStrikeReaderImpl:
CEDAR
PROGRAM
IMPORTS UFFileManager, Graphics, GraphicsOps, UnifiedFonts
EXPORTS UFStrikeReader
= BEGIN OPEN UFStrikeReader;
FONT: TYPE = UnifiedFonts.FONT;
OpenInitialization: UFFileManager.InitProc =
TRUSTED {
This gets called when the font file is first opened; its responsibility is to build a description of the font acceptable to Graphics.
fontRef: Graphics.FontRef ← GraphicsOps.UnsafeNewFont[fontFile.Pointer[]];
RETURN[fontRef];
};
DrawChar:
PUBLIC
PROCEDURE [context: Graphics.Context, key: Key, char:
CHAR] =
TRUSTED {
file: UFFileManager.FontFile ← UFFileManager.Open[key, OpenInitialization];
fRef: CGFont.Ref ← NARROW[file.GetData[]];
fontRef: Graphics.FontRef ← LOOPHOLE[fRef];
Graphics.DrawChar[context, char, fontRef];
};
BoundingBox:
PUBLIC
PROCEDURE [key: Key, char:
CHAR]
RETURNS [box: UnifiedFonts.Box] =
TRUSTED {
file: UFFileManager.FontFile ← UFFileManager.Open[key, OpenInitialization];
fRef: CGFont.Ref ← NARROW[file.GetData[]];
fontRef: Graphics.FontRef ← LOOPHOLE[fRef];
[box.xmin, box.ymin, box.xmax, box.ymax] ← Graphics.CharBox[fontRef, char];
};
WidthVector:
PUBLIC
PROCEDURE [key: Key, char:
CHAR]
RETURNS [vec: UnifiedFonts.Vec] =
TRUSTED {
file: UFFileManager.FontFile ← UFFileManager.Open[key, OpenInitialization];
fRef: CGFont.Ref ← NARROW[file.GetData[]];
fontRef: Graphics.FontRef ← LOOPHOLE[fRef];
[vec.x, vec.y] ← Graphics.CharWidth[fontRef, char];
};
FontGraphicsClass interface
SKDrawChar:
PROCEDURE [font:
FONT, char:
CHAR, context: Graphics.Context] = {
DrawChar[context, font.graphicsKey, char];
};
SKBoundingBox:
PROCEDURE [font:
FONT, char:
CHAR]
RETURNS [box: UnifiedFonts.Box] = {
box ← BoundingBox[font.graphicsKey, char];
};
SKWidthVector:
PROCEDURE [font:
FONT, char:
CHAR]
RETURNS [vec: UnifiedFonts.Vec] = {
vec ← WidthVector[font.graphicsKey, char];
};
SKContains:
PROCEDURE [font:
FONT, char:
CHAR]
RETURNS [
BOOLEAN] = {
RETURN[WidthVector[font.graphicsKey, char]#[0,0]];
};
SKGraphicsObjectInit:
PROCEDURE [font:
FONT] = {
file: UFFileManager.FontFile ← UFFileManager.Open[font.graphicsKey, OpenInitialization];
fRef: CGFont.Ref ← NARROW[file.GetData[]];
font.fontGraphicsClass ← SKGraphicsClass;
font.bc ← fRef.min;
font.ec ← fRef.max;
};
SKGraphicsClass:
REF UnifiedFonts.FontGraphicsClassRec←
NEW[UnifiedFonts.FontGraphicsClassRec←[
drawCharProc: SKDrawChar,
boundingBoxProc: SKBoundingBox,
widthVectorProc: SKWidthVector,
containsProc: SKContains
]];
FontFormattingClass interface
LigatureOrKern: TYPE = UnifiedFonts.LigatureOrKern;
Box: TYPE = UnifiedFonts.Box;
SKLigKern: PROCEDURE [font: FONT, char1, char2: CHAR] RETURNS [ligatureOrKern: LigatureOrKern] = {RETURN[[neither[]]]};
SKFormattingBox:
PROCEDURE [font:
FONT, char:
CHAR]
RETURNS [box: Box] = {
box ← BoundingBox[font.graphicsKey, char];
box.xmin ← 0;
box.xmax ← WidthVector[font.graphicsKey, char].x;
};
SKFormattingMetric:
PROCEDURE [font:
FONT, metric:
ATOM, char:
CHAR]
RETURNS [
REAL] = {
RETURN[0.0];
};
SKFormattingObjectInit:
PROCEDURE [font:
FONT] = {
font.fontFormattingClass ← SKFormattingClass;
};
SKFormattingClass:
REF UnifiedFonts.FontFormattingClassRec ←
NEW[UnifiedFonts.FontFormattingClassRec←[
formattingBoxProc: SKFormattingBox,
ligKernProc: SKLigKern,
formattingMetricProc: SKFormattingMetric
]];
UnifiedFonts.RegisterFontGraphicsClass[$Strike, SKGraphicsObjectInit];
UnifiedFonts.RegisterFontFormattingClass[$Strike, SKFormattingObjectInit];
END.