ImagerMaskCache.mesa
Copyright Ó 1986, 1987, 1989, 1991 by Xerox Corporation. All rights reserved.
Michael Plass, September 14, 1989 10:10:53 am PDT
Doug Wyatt, May 19, 1985 4:06:38 pm PDT
DIRECTORY
ImagerDeviceVector USING [ScaledVec],
ImagerFont USING [Font, CorrectionType, XChar],
ImagerManhattan USING [Polygon],
ImagerSample USING [SampleMap],
Prop USING [PropList],
SF USING [Box, BoxAction, maxBox, Vec, zeroVec];
ImagerMaskCache: CEDAR DEFINITIONS
~ BEGIN
XChar: TYPE ~ ImagerFont.XChar;
Device-dependent Character Masks
Run: TYPE ~ MACHINE DEPENDENT RECORD [fMin: CARD16, lastRun: BOOL, fSize: NAT15];
Same as PDFileFormat.Run; fMin is relative to box.min.f.
ScaledVec: TYPE ~ ImagerDeviceVector.ScaledVec;
CharFlags: TYPE ~ MACHINE DEPENDENT --PACKED-- RECORD [
amplified: BOOL,
correction: ImagerFont.CorrectionType,
missing: BOOL -- this character was missing from the font
];
CharMask: TYPE ~ REF CharMaskRep;
CharMaskRep: TYPE ~ RECORD [
font: ImagerFont.Font, -- font and char together provide a unique identifier for this mask
char: ImagerFont.XChar,
escapement: ScaledVec,
box: SF.Box,
flags: CharFlags,
data: SELECT rep: * FROM
raster => [bits: SEQUENCE length: CARDINAL -- sSize*Ceiling[REAL[fSize]/BITS[WORD]] -- OF WORD],
runs => [run: SEQUENCE nRuns: CARDINAL OF Run],
culled, maskNotCacheable => [],
ENDCASE
];
BitmapFromCharMask: PROC [charMask: CharMask] RETURNS [ImagerSample.SampleMap];
BoxesFromCharMask: PROC [charMask: CharMask, boxAction: SF.BoxAction, delta: SF.Vec ¬ SF.zeroVec, clip: SF.Box ¬ SF.maxBox];
RasterCharMaskFromSampleMap: PROC [map: ImagerSample.SampleMap] RETURNS [REF CharMaskRep.raster];
Does not fill in font, char, escapement or flags
RasterCharMaskFromManhattan: PROC [p: ImagerManhattan.Polygon, bb: SF.Box] RETURNS [REF CharMaskRep.raster];
Does not fill in font, char, escapement or flags
RunsCharMaskFromManhattan: PROC [p: ImagerManhattan.Polygon, bb: SF.Box, nRuns: INT] RETURNS [REF CharMaskRep.runs];
Does not fill in font, char, escapement or flags
CountRuns: PROC [p: ImagerManhattan.Polygon] RETURNS [INT];
This version includes zero-length runs needed to get the PD-style run representation to work.
Character Mask Caches
MakeCharMaskProc: TYPE ~ PROC [parameters: Parameters, font: ImagerFont.Font, char: ImagerFont.XChar] RETURNS [CharMask];
CostParameters: TYPE ~ RECORD [slope: REAL, offset: REAL];
These parameters are used (as a hint) for deciding on which cached repersentation to use. For each of the possible representation the cost is calculated as (slope*WORDS[rep]+offset), and the representation of lowest cost is selected.
Parameters: TYPE ~ REF ParametersRep;
This collection of parameters is available for use by higher-level software; except for the cache management parameters, the cache implementation does not itself use the parameters.
ParametersRep: TYPE ~ RECORD [
Cache management parameters:
sizeLimit: NAT ¬ 4000,
Mask creation hook:
makeCharMask: MakeCharMaskProc ¬ NIL, -- For font-tuning hooks
Representation selection parameters:
rasterCost: CostParameters ¬ [slope: 1, offset: 0],
runsCost: CostParameters ¬ [slope: 1, offset: 0],
uncacheableCost: CostParameters ¬ [slope: 0, offset: 2000],
Folio:
spotSize: REAL ¬ 1.0,
Font Solution:
sThicken: REAL ¬ 0.0,
fThicken: REAL ¬ 0.0,
sMinThickness: REAL ¬ 0.0,
fMinThickness: REAL ¬ 0.0,
sHalfbit: BOOL ¬ FALSE,
fHalfbit: BOOL ¬ FALSE,
Extension:
propList: Prop.PropList
];
MaskCache: TYPE ~ REF MaskCacheRep;
MaskCacheRep: TYPE;
Create: PROC [param: ParametersRep ¬ []] RETURNS [MaskCache];
Makes a new cache
Size: PROC [x: MaskCache] RETURNS [NAT];
Actual number of elements in the cache.
Fetch: PROC [x: MaskCache, font: REF, char: XChar] RETURNS [CharMask];
Returns NIL if the entry is not in the cache.
GetParameters: PROC [x: MaskCache] RETURNS [Parameters];
Treat these Parameters as read-only.
UpdateParameters: PROC [x: MaskCache, action: PROC [Parameters]];
The action proc is called (probably under a monitor!) to access or change the parameters.
Changes that cause different masks to be generated should be followed by a Flush.
Store: PROC [x: MaskCache, charMask: CharMask];
Since this is a cache, the implementation reserves the right to replace previously existing entries.
Flush: PROC [x: MaskCache];
Makes the cache empty.
Launder: PROC [x: MaskCache, keep: PROC [CharMask] RETURNS [BOOL]];
Calls keep procedure for each CharMask, and retains only those masks for which keep returns TRUE.
GetList: PROC [x: MaskCache] RETURNS [LIST OF CharMask];
In case somebody wants to save the cache somewhere else.
GetNamedCache: PROC [atom: ATOM] RETURNS [MaskCache];
For sharing caches by name.
SetNamedCacheParameters: PROC [atom: ATOM, p: ParametersRep];
For initializing the parameters in a shared font cache.
FlushAll: PROC;
Flushes all the named caches.
smallCacheSize: NAT ~ 256;
SmallCache: TYPE = REF ARRAY [0..smallCacheSize) OF REF CharMaskRep.raster;
ObtainSmallCache: PROC [x: MaskCache] RETURNS [SmallCache]; -- might return NIL.
ReleaseSmallCache: PROC [x: MaskCache, s: SmallCache];
A small cache is owned by a single process for the duration of a Show.
END.