Emulation of the setstrokeadjust Operator

Similar documents
Font Switching Optimizations

Supporting Level 2 Functionality

Level 2 Compatibility: The setscreen and currentscreen Operators

Simple Text Setting Calculations for PostScript Language Drivers

Emulation of the execform Operator

Using save Outside the Server Loop

Timing Techniques. Adobe Developer Support. Technical Note # March Adobe Systems Incorporated

The StemSnap Hint Operator for Type 1 Font Programs

Supporting Device Features

Supporting Data Compression in PostScript Level 2 and the filter Operator

Acrobat Widths-Only CIDFont Tutorial ADOBE SYSTEMS INCORPORATED

Hello world. 2. Stack-based Programming. Oscar Nierstrasz

Postscript Intro. References. What is Postscript? Hello World! in Ghostscript. CSE 413, Autumn 2005 Programming Languages. Page description language

CID-Keyed Font Technology Overview

Drawing polygons: loops and arrays

WHAT. %!PS-Adobe-3.0. structure and code requirements. DSC = comments + In This Issue

Printer Systems-Based Separations

Improving Image Performance by Using Color Lookup Tables

Color Separation Conventions for PostScript Language Programs

Reader. PDF Writer. PostScript File. Distiller. Control whether or not the Save File As dialog box is displayed.

Informatique Graphique. Traitement de l'information et automatisation. Traitement de l'information et automatisation

References. Topic #15: Postscript Intro. What is Postscript? Hello World! in Ghostscript. Page Description Language. Hello World!

Adobe Serial and Parallel Communications Protocols Specification

Drawing curves automatically: procedures as arguments

Drawing polygons: loops and arrays

Postscript Control Flow

A Short Introduction to PostScript

The Adobe-CNS1-6 Character Collection

Project 1 Using Lex and Yacc for Higher Level Abstraction CISC 471 Compiler Design

PostScript Printer Description File Format Specification

Package epsdice a scalable dice font

Everything You Wanted to Know About Adobe Acrobat Annotation Handlers But Were Afraid to Ask

Text and Graphics. Postcript is a Page Description Language! Paths

PostScript Language Document Structuring Conventions Specification

User s Guide to Creating PDFs for the Sony Reader

Emulation of the makepattern and setpattern Operators

The Acrobat Exchange. In This Issue

HP DesignJet 3500CP Printing Guide for Windows

Tips for Working with the New PostScript Printer Driver for Macintosh

Photofont Start 2.0. for Macintosh and Windows. User Manual

FontLab. TECHNICAL NOTE #002 (Mac) Keyboard shortcuts. Copyright 2001 FontLab Ltd. THE DIGITAL TYPE DESIGN TOOLKIT

0Harlequin RIP. Named Color Databases. Technical Note Hqn039 June 2001

A Short Introduction to PDF

Recording Output Intentions for Color Critical Workflows ADOBE SYSTEMS INCORPORATED

Display PostScript System

Roadmap for tonight. What are Bezier curves (mathematically)? Programming Bezier curves (very high level view).

Adobe. Type Manager 4.1. User Guide

PostScript Internals Graphics II Spring 1999

SDK White Paper. HLSL Blood Shader Gravity Maps

White Paper. Denoising. February 2007 WP _v01

Font information interchange -- Part 3: Glyph shape representation Amendment 2: Additional Shape Representation Technology for Open Font Format

KIMOTO K I M O S E T T E R R I P. Kimosetter RIP User Guide 1. Revised: February 2015 U SER GUID E (FOR W INDOWS 7 )

Conversion SDK v11 32-bit and 64-bit

Paths. "arc" (elliptical or circular arc), and. Paths are described using the following data attributes:

Using the printer with Windows 3.1

Evaluation of postfix

Matlab Plots in Microsoft Word

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

FirePoint 8. Setup & Quick Tour

Informatik Image Markup

INKSCAPE BASICS. 125 S. Prospect Avenue, Elmhurst, IL (630) elmhurstpubliclibrary.org. Create, Make, and Build

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Acrobat Exchange Interapplication Communication

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Thank you very much for purchasing this product.

Display PostScript System

White Paper. Solid Wireframe. February 2007 WP _v01

Adobe Photoshop Sh S.K. Sublania and Sh. Naresh Chand

Box It Up (A Graphical Look)

DK2. Handel-C code optimization

Quick Reference Manual

Uniface Printing A White Paper by Debbra Mullen

CHAPTER 1 COPYRIGHTED MATERIAL. Getting to Know AutoCAD. Opening a new drawing. Getting familiar with the AutoCAD and AutoCAD LT Graphics windows

Sage Financial Reporter User's Guide

x10data Smart Client 6.5 for Windows Mobile Installation Guide

CorelDRAW X7. Kogent Learning Solutions Inc. Authored by: Published by:

Adobe Acrobat Reader Help

Web-Friendly Sites. Planning & Design 1

Let s Make a Front Panel using FrontCAD

Disclaimer; No Warranty Copyright Trademarks

Personalizing CA Clarity PPM User Guide. Release

IMAGE STUDIO LITE. Tutorial Guide Featuring Image Studio Analysis Software Version 3.1

Overview: Printing MFworks Documents

Sage Fixed Assets Reporting. User Guide

AppleScript Finder Guide. English Dialect

Graphical Analysis. Figure 1. Copyright c 1997 by Awi Federgruen. All rights reserved.

(Refer Slide Time: 00:02:02)

DataFlash and Serial Flash BGA Package. Design Note. DataFlash and Serial Flash BGA Package. Introduction

SDK White Paper. Vertex Lighting Achieving fast lighting results

Kimosetter RIP. User Guide (for Windows) Kimosetter RIP User Guide. Revised: July, 2007

Histogram calculation in OpenCL. Victor Podlozhnyuk

How to Split PDF files with AutoSplit

Data Representation From 0s and 1s to images CPSC 101

Getting Started with Transparency

WARNING for Autumn 2004:

Lenovo RAID Introduction Reference Information

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

Dolphin PartMaster Wire EDM

Chapter 8: Implementation- Clipping and Rasterization

anatomy cap height x-height baseline descender ligature finial terminal ascender spine small capital uppercase counter cross bar lowercase

Transcription:

Emulation of the setstrokeadjust Operator Adobe Developer Support Technical Note #5111 31 March 1992 Adobe Systems Incorporated Adobe Developer Technologies 345 Park Avenue San Jose, CA 95110 http://partners.adobe.com/ PN LPS5111

Copyright 1991 1992 by Adobe Systems Incorporated. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of the publisher. Any software referred to herein is furnished under license and may only be used or copied in accordance with the terms of such license. PostScript, the PostScript logo, Display PostScript, and the Adobe logo are trademarks of Adobe Systems Incorporated which may be registered in certain jurisdictions. Other brand or product names are the trademarks or registered trademarks of their respective holders. This publication and the information herein is furnished AS IS, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies, makes no warranty of any kind (express, implied or statutory) with respect to this publication, and expressly disclaims any and all warranties of merchantability, fitness for particular purposes and noninfringement of third party rights.

Contents Emulation of the setstrokeadjust Operator 5 1 Introduction 5 2 Device Space and Stroke Adjustment 5 The Problem 5 A Solution 7 Level 2 Automatic Stroke Adjustment 9 3 Emulating Automatic Stroke Adjustment for Level 1 9 Installing Emulations 9 Saving VM 10 Naming Possibly Emulated Operators 11 The Emulations 11 Using The Emulations 16 4 Performance 17 Stroke Adjusting Absolute Versus Relative Operators 17 Stroke Adjusting Using Rectangles 18 5 Summary 19 Appendix A: Spreadsheet Program Examples 21 Appendix B: Changes Since Earlier Versions 25 Index 27 iii

iv Contents (31 Mar 92)

Emulation of the setstrokeadjust Operator 1 Introduction PostScript Level 2 makes many new features available to applications programmers. One new feature is the ability to do stroke adjustment automatically without any degradation of performance. Stroke adjustment makes a major improvement in the appearance of a large class of documents. Many applications already implement stroke adjustment for use on Level 1 systems. Providing automatic stroke adjustment in a way that does not require an application to know whether it is using this feature on a Level 2 system or an emulation on a Level 1 system, is quite straightforward. 2 Device Space and Stroke Adjustment 2.1 The Problem Lines that have the same width specified in a PostScript language program might be rendered in device space at two different widths. Any pixel partly or completely included in the width of a line in device space is considered part of the line. Because paths may fall on arbitrary locations within pixel boundaries, the number of pixels turned on when stroking a line of a given width can vary by one pixel, depending on where in device space relative to pixel boundaries the line happens to fall. Figure 1 Mapping of s to device space in user space in user space in user space in user space path path path path in device space in device space in device space in device space 5

Figure 1 shows a line with a user space width of less than a pixel being rendered as both one pixel and two pixels wide in device space. A line with a user space width that amounts to one and some fraction of a pixel wide in device space can be rendered as either two or three pixels wide, and so on. This one pixel difference in is readily detected by eye at 300 dpi and can be seen when comparing even relatively wide lines. The consistency problem is apparent in stroking curved lines as well as straight ones. Figures 2 and 3 demonstrate this problem with a common application of straight lines: imaging spreadsheets. Figure 2 A spreadsheet drawn without stroke adjustment 6 Emulation of the setstrokeadjust Operator (31 Mar 92)

Figure 3 A spreadsheet drawn with stroke adjustment Demonstration programs for stroke adjusted spreadsheet examples are included in Appendix A. 2.2 A Solution User space paths can be coerced to fall at consistent locations within device space pixel boundaries, guaranteeing a consistent appearance for lines of a similar width. This can be done by converting user space coordinates to device space coordinates, adjusting the location relative to pixel boundaries, and then converting back to user space for use in path construction. Figure 4 Stroke adjustment 2 Device Space and Stroke Adjustment 7

A desirable position within the pixel is one quarter pixel over and up from the bottom left corner. Adjustment can be made by subtracting one quarter pixel from the device space coordinate value, rounding to the nearest whole pixel, and adding one quarter pixel. Why adjust to one quarter? Placing the path off center within the pixel makes it possible for the device space to grow one pixel at a time as the specified increases. Placing the path along the pixel boundary forces all s to use an even number of pixels and to grow two pixels at a time. Centering the path within the pixel forces all s to use an odd number of pixels and also to grow two pixels at a time. Figure 5 Positioning of path coordinates within pixels in user space in user space in user space path path path in device space in device space in device space in user space in user space in user space path path path in device space in device space in device space Rounded to pixel boundary: Rounded to.25 pixel: even/odd Rounded to midpoint: odd pixel even pixel widths pixel widths widths The uniform appearance of lines with similar widths is sometimes achieved at the expense of causing the spaces between the lines, which may have been of uniform width, to vary instead. This variation is normally much less noticeable than a variation in the width of the lines themselves. Note A more complete explanation of the mapping of a user space path to device space pixels can be found in Programming the Display PostScript System with NeXTstep, Chapter 3, The Coordinate System. 8 Emulation of the setstrokeadjust Operator (31 Mar 92)

2.3 Level 2 Automatic Stroke Adjustment Both PostScript Level 2 systems and Display PostScript systems are able to perform an automatic adjustment to paths that causes them to be rendered at uniform widths. This automatic stroke adjustment can be turned on and off with the setstrokeadjust operator. Stroke adjusted paths are actually rendered slightly faster on Level 2 systems than non-stroke adjusted paths, so that you might want to stroke adjust paths for performance reasons alone, even when the improved appearance is not a consideration. Language level compatibility strategies are discussed in Appendix D of the PostScript Language Reference Manual, Second Edition, and in Technical Note #5110, Supporting PostScript Level 2 Functionality. One highly recommended way to achieve language level compatibility involves including a procedure set in the prolog that installs the desired extended features where available, and emulations where not, into an interface layer providing uniform access to the features. This method is fully portable. It makes the feature available whether or not a particular interpreter provides it and allows the Level 1/Level 2 issue to remain transparent to the application, thus lessening the complexity of its code. Automatic stroke adjustment is a feature readily provided using this compatibility technique. 3 Emulating Automatic Stroke Adjustment for Level 1 Level 1 emulations of Level 2 features should be defined and installed as a function of whether or not the desired features exist on the target interpreter. If this is known in advance, only the procedure set intended for that system must be downloaded. If not (as when sending to a spooler or saving to a disk file), both sets must be included, and the installation decision must be made on the interpreter side. 3.1 Installing Emulations The following are recommendations for determining which procedure set to install. Use where rather than known when checking for the existence of PostScript language operators, because it is more general and does not require the hard coding of a dictionary name. Use known when checking for application-defined procedures to avoid possible name confusion with other applications or additional extensions to the PostScript language. It should refer to the application s own dictionary. Use the languagelevel operator when all required Level 2 operator emulations are to be installed as a group. languagelevel is found only on Level 2 and must be used in conjunction with where. 3 Emulating Automatic Stroke Adjustment for Level 1 9

/languagelevel where {pop languagelevel} {1} ifelse 2 lt { %use emulations }{ %load existing operators } ifelse This is not an appropriate method to use when the desired Level 2 features may also exist as extensions to Level 1 as, for example, automatic stroke adjustment does on Display PostScript systems. Use where to test for the presence of a tell-tale operator when a related group of Level 2 operators might be present as extensions to Level 1 systems. Automatic stroke adjustment is available on both Level 2 and Display PostScript systems. A Display PostScript system can be either Level 1 or Level 2. A Level 1 Display PostScript system has automatic stroke adjustment, but does not have the languagelevel operator. The emulation examples shown below test for the presence of the setstrokeadjust operator, rather than for languagelevel. Note Some indications of which language extensions are available on which implementations can be found in Appendix A of the PostScript Language Reference Manual, Second Edition. PostScript printer description (PPD) files indicate exactly which extensions are available on a specific printer in human-readable, machine-parseable form. PPD files and their use are discussed in Technical Notes #5003, PostScript Printer Description Files Specification, Version 4.0, and #5117, Supporting Device Features. 3.2 Saving VM The following examples used a somewhat more sophisticated approach for installing a procedure set into the interface layer than the method described in section 3.1. Instead, the test is used to set a Boolean, Level2 DPS, which is used with save and restore pairs to avoid occupying memory with unused procedure sets. Some 240 bytes are saved on Level 1 by doing a save/restore bracket around the Level 2 procedure set for the smaller absolute set of example code. As more sets of feature emulation procedures come to be used by applications, strategies to avoid filling up VM with unused definitions play a larger role in providing more room for procedures doing useful work. 10 Emulation of the setstrokeadjust Operator (31 Mar 92)

3.3 Naming Possibly Emulated Operators As shown in section 3.4, an interface layer using short names bound conditionally either to emulations or to PostScript language operators can be defined, which in turn can be used to output a page description that will execute on any interpreter. The usual reason to use short names is to reduce the length of the program being sent to the device because this can often make a noticeable improvement in speed. It is also important not to give an emulation the same name as an operator to avoid letting an embedded program assume that a PostScript language operator is available when it is not. This is especially critical when an operator has been only partially emulated and might not behave the way the embedded program expects. There is a discussion on this topic in Appendix D of the PostScript Language Reference Manual, Second Edition. 3.4 The Emulations To approximate the adjustment done automatically by Level 2, it is necessary to perform the following operations for each coordinate of the path to be adjusted. 1. Convert the user space coordinates to device space. 2. Round the coordinates to the one quarter pixel location as described previously. 3. Convert the rounded coordinates back to user space and use for the path construction. 3 Emulating Automatic Stroke Adjustment for Level 1 11

The procedure set in Example 1 performs this sort of stroke adjusted path construction for absolute path construction operators. %%BeginProlog % Example 1 % automatic stroke adjustment already available? /Level2 DPS /setstrokeadjust where {pop true} {false} ifelse def Level2 DPS not {save} if % remove procset if not needed Level2 DPS { %%BeginResource: procset Adobe_SpecialGraphics_Level2 DPS 1.0 0 /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /Rt /rectstroke load def /GRinit {} def /SA /setstrokeadjust load def %%EndResource } if Level2 DPS not {restore} if Level2 DPS {save} if % remove procset from VM if not needed Level2 DPS not { %%BeginResource: procset Adobe_SpecialGraphics_L1 1.0 0 /GRdict 5 dict def GRdict begin /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /Rt { % x y w h Rt - rectangle 4-2 roll moveto % bottom left hand corner dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath /SA { % true, false SA - setstrokeadjust {mark countdictstack 2 sub {currentdict GRdict eq {SAdict begin exit} {currentdict end} ifelse} repeat counttomark {begin} repeat pop} {mark countdictstack 2 sub {currentdict SAdict eq {end exit} {currentdict end} ifelse} repeat counttomark {begin} repeat pop } ifelse end % GRdict /GRinit { % put GRdict on dictionary stack under userdict countdictstack array dictstack cleardictstack dup 0 GRdict put {begin} forall 12 Emulation of the setstrokeadjust Operator (31 Mar 92)

/SAdict 5 dict def SAdict begin % snap user space location to device space pixel /snaptopixel { % x y snaptopixel sx sy transform.25 sub round.25 add exch.25 sub round.25 add exch itransform /Mt { % x y MT - moveto snaptopixel moveto /Lt { % x y LT - lineto snaptopixel lineto /Ct { % x y CT - curveto snaptopixel curveto % note control points are not snapped /Rt { % x y w h Rt - rectangle 4-2 roll Mt % bottom left hand corner dtransform round exch round exch idtransform % round h and w dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath end % SAdict %%EndResource } if Level2 DPS {restore} if... other procset definitions... %%EndProlog Example 1 deals only with absolute path construction operators. A more general emulation that includes relative path operators can also be defined at the cost of having to maintain some location context from operator to operator. Performing a relative move from an altered location rather than from the originally specified location can result in landing in a different pixel than the one actually indicated by the path. Performing a series of relative path operations, without correcting the location differences caused by rounding, results in a noticeable accumulated error. 3 Emulating Automatic Stroke Adjustment for Level 1 13

The code in Example 2 includes emulations for the relative path operators and avoids this incorrect behavior. %%BeginProlog % Example 2 /Level2 DPS /setstrokeadjust where {pop true} {false} ifelse def Level2 DPS not {save} if Level2 DPS { %%BeginResource: procset Adobe_SpecialGraphicsRel_Level2DPS 1.0 0 /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /RM /rmoveto load def /RL /rlineto load def /RC /rcurveto load def /Rt /rectstroke load def /GRinit {} def /SA /setstrokeadjust load def %%EndResource } if Level2 DPS not {restore} if Level2 DPS {save} if Level2 DPS not { %%BeginResource: procset Adobe_SpecialGraphicsRel_L1 1.0 0 /GRdict 8 dict def GRdict begin /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /RM /rmoveto load def /RL /rlineto load def /RC /rcurveto load def /Rt { % x y w h Rt - rectangle 4-2 roll moveto % bottom left hand corner dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath /SA { % true, false SA - setstrokeadjust {mark countdictstack 2 sub {currentdict GRdict eq {SAdict begin exit} {currentdict end} ifelse} repeat counttomark {begin} repeat pop} {mark countdictstack 2 sub {currentdict SAdict eq {end exit} {currentdict end} ifelse} repeat counttomark {begin} repeat pop } ifelse end % GRdict 14 Emulation of the setstrokeadjust Operator (31 Mar 92)

/GRinit { % put GRdict on dictionary stack under userdict countdictstack array dictstack cleardictstack dup 0 GRdict put {begin} forall /SAdict 9 dict def SAdict begin % snap user space location to device space pixel /snaptopixel { % x y snaptopixel sx sy transform.25 sub round.25 add exch.25 sub round.25 add exch itransform % save absolute user space location for next relative operator /savelocation { % x y savelocation x y 2 copy /uy exch def /ux exch def /Mt { % x y MT - moveto savelocation snaptopixel moveto /Lt { % x y LT - lineto savelocation snaptopixel lineto /Ct { % x1 y1 x2 y2 x3 y3 CT - curveto savelocation snaptopixel curveto % note control points are not snapped /RM { % dx dy RM - rmoveto exch ux add exch uy add % convert dx dy to user space absolute savelocation snaptopixel moveto /RL { % dx dy RL - rlineto exch ux add exch uy add savelocation snaptopixel lineto /RC { % x1 y1 x2 y2 x3 y3 RC - rcurveto 3 { 6 1 roll ux add 6 1 roll uy add } repeat savelocation snaptopixel curveto % note control points are not snapped /Rt { % x y w h Rt - rectangle 4-2 roll Mt % bottom left hand corner dtransform round exch round exch idtransform % round h and w dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath end % SAdict %%EndResource } if Level2 DPS {restore} if... other procset definitions... %%EndProlog 3 Emulating Automatic Stroke Adjustment for Level 1 15

The control points of the curveto and rcurveto operator emulations are not coerced to one quarter pixel, although the endpoints are. Coercing the control points nearly triples the work being done, for no real gain in appearance. The one exception is when the curve is actually a straight line (where the endpoints and control points are colinear). It might be necessary to reposition the control points to get the right thing to happen. Since it is not efficient to use curveto to render a straight line at the best of times, it is preferable to keep curveto emulations simple and use a line operator for lines. Two letter procedure names are used for procedures to be invoked by our hypothetical driver. Longer, more readable names are for definitions used only within the prolog. 3.5 Using The Emulations Before the automatic stroke adjustment emulations can be used, the special graphics dictionary must be installed. To do this, call GRinit in the document setup section. Once this is done, an application can use the stroke adjustment interface layer for all stroked paths. The interface operators, SA (setstrokeadjust), Mt (moveto), Lt (lineto), and so on, work as their counterparts do. A typical use might be: %%BeginSetup GRinit... some other setup code here... %%EndSetup true SA % set stroke adjustment 84 104 Mt 84 738 Lt... and so on... An application might also place true SA in the setup section and then use the procedure set definitions for every stroked path in the document. This is an acceptable basic approach. Given that Level 2 systems run faster with stroke adjustment set, it will probably be common on Level 2 to do this whether or not the adjustment is considered necessary to the appearance of the output. The default value for SA on both Level 1 and Level 2 printers is false (stroke adjustment not enabled). For more on the setstrokeadjust operator, see section 6.5.2 and page 512 of the PostScript Language Reference Manual, Second Edition. Using the stroke adjusted emulations provides the stroke adjusting on Level 1 systems (other than Display PostScript systems), not the setstrokeadjust operator. The interface operators for stroking paths must be used to produce the same appearance on both Level 1 and Level 2 systems. Note The font handling mechanism performs the stroke adjustment positioning automatically for fonts on all PostScript interpreters. As a result, the moveto operator used to set the current point before a show operation does not need to be stroke adjusted. 16 Emulation of the setstrokeadjust Operator (31 Mar 92)

4 Performance As has been mentioned previously, using automatic stroke adjustment for paths on Level 2 is somewhat faster than not stroke adjusting paths. Optimizing stroke adjustment on Level 2 is not an issue. Improving the speed of stroke adjustment on Level 1 is an a topic worthy of discussion. A fully general emulation of automatic stroke adjustment, used with no attempts to exploit known regularities in an application s output, can in the worst case increase the time it takes to render a path by three and a half to four times. Real gains are possible here when the special needs of particular applications are considered. The result of applying different approaches to the task of drawing the spreadsheet graphic (shown earlier) appear in Table 1. Table 1 Times (in milliseconds) for drawing the spreadsheet 20 times Relative Absolute Rectangle Procedure set procedures procedures procedures absolute plus relative 6730 6256 4194 absolute only 5500 3994 no stroke adjust 1831 1987 2559 4.1 Stroke Adjusting Absolute Versus Relative Operators In the two procedure set examples given previously for automatic stroke adjustment emulation, Example 1 provides emulations for absolute operators only, while Example 2 includes both absolute (moveto, lineto, curveto) and relative (rmoveto, rlineto, rcurveto) operators. In Example 2, not only do the absolute path operators have to save some state for the relative operators, but the relative operators must get that information and update it before using it. The relative operators are more expensive to use by about 9 percent than their absolute cousins in Example 2. This figure does not include the use of the rcurveto emulation. When only absolute path operations are to be stroke adjusted, as in the Example 1 emulations, it is unnecessary to update and save state information about location for the relative operators. Using the Example 1 absolute procedures is more efficient than using the Example 2 absolute procedures, resulting in an additional savings of about 12 percent. 4 Performance 17

Which emulation set to use depends on the known demands of a particular application. In some cases, the convenience of the relative operators may be worth their additional cost. In general, the absolute operator only procedure set of Example 1 offers the most performance. 4.2 Stroke Adjusting Using Rectangles Further savings are possible if an application can cast its graphics output in the form of rectangles. Using rectangles whenever possible is especially advantageous when performing stroke adjustment. Only one point needs full stroke adjustment, plus one distance vector rounded in device space, as opposed to the four full stroke adjustments required for an equivalent figure. A stroke adjusted rectangle is less than 50% slower than a non-stroke adjusted rectangle. Stroke adjusted rectangles become especially cheap when compared to drawing with no rectangle procedure: less than 25% slower than the non-stroke adjusted, no-rectangle procedure approach. The size of the advantage varies depending on the printer and communications channel. See Technical Note #5126, PostScript Language Code Optimization: Rectangles, for a timing study examining rectangle drawing. Though drawing the spreadsheet as a series of rectangles rather than as two sets of parallel lines requires enough extra work (many more path operations) that there appears to be a disadvantage shown in the non-stroke adjusted times, using them is still cheaper by some 40 percent when stroke adjusting. Stroke adjusted rectangle procedures are included in both the absolute and absolute plus relative procedure sets above and were used in the spreadsheet drawing time example. Both the procedure set definitions of Rt load the rectstroke operator on Level 2 systems. Neither of the corresponding stroke adjusting emulations is a complete emulation of the Level 2 operator. For more information on emulating Level 2 rectangle operators, see Technical Note #5123, Emulation of the rectclip, rectfill, and rectstroke Operators. 18 Emulation of the setstrokeadjust Operator (31 Mar 92)

5 Summary The location of a path within a pixel can cause lines with the same to have a different width in pixels. This can cause unattractive results when a grid or other symmetrical group of lines is drawn on lower resolution devices. PostScript Level 2 and Display PostScript systems can adjust the path location automatically to produce lines with a uniform pixel width. This adjustment may be turned on and off with the setstrokeadjust operator, and actually increases the speed of path operators. For applications to take advantage of automatic stroke adjustment without losing Level 1 compatibility, it is necessary to install emulations that perform stroke adjustment when automatic stroke adjustment is not available. The performance cost of stroke adjusting a path on Level 1 systems varies from one and one half to three and one half times not doing so. The benefits of using the emulations are a uniform appearance on Level 1 or Level 2, and the preservation of device and resolution independence. 5 Summary 19

20 Emulation of the setstrokeadjust Operator (31 Mar 92)

Appendix A: Spreadsheet Program Examples A stroke adjusted spreadsheet drawn with two sets of parallel lines: %!PS-Adobe-3.0 %%Title: Spreadsheet drawn using Mt Lt %%Creator: RH %%CreationDate: March 20, 1991 %%EndComments %%BeginProlog % automatic stroke adjustment already available? /Level2 DPS /setstrokeadjust where {pop true} {false} ifelse def Level2 DPS not { save } if % remove procset if not needed Level2 DPS % def interface for Level 2 { %%BeginResource: procset Adobe_SpecialGraphics_L2DPS 1.0 0 /GRinit {} def /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /Rt /rectstroke load def /SA /setstrokeadjust load def %%EndResource } if Level2 DPS not { restore } if Level2 DPS { save }if % remove procset from VM if not % needed Level2 DPS not { % emulations are needed %%BeginResource: procset Adobe_SpecialGraphics_L1 1.0 0 /GRdict 5 dict def GRdict begin /Mt /moveto load def /Lt /lineto load def /Ct /curveto load def /Rt { % x y w h Rt - basic rectangle 4-2 roll moveto % bottom left hand corner dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath /SA { % true,false SA - enable/disable stroke adjustment { mark countdictstack 2 sub {currentdict GRdict eq {SAdict begin exit} 21

{currentdict end} ifelse} repeat counttomark {begin} repeat pop} { mark countdictstack 2 sub {currentdict SAdict eq {end exit} {currentdict end} ifelse } repeat counttomark {begin} repeat pop } ifelse end % GRdict /GRinit { % put GRdict on stack under userdict countdictstack array dictstack cleardictstack dup 0 GRdict put { begin} forall /SAdict 10 dict def SAdict begin % snap user space location to device space pixel /snaptopixel { % x y snaptopixel sx sy transform.25 sub round.25 add exch.25 sub round.25 add exch itransform /Mt { % x y Mt - moveto snaptopixel moveto /Lt { % x y Lt - lineto snaptopixel lineto /Ct { % x1 y1 x2 y2 x3 y3 Ct - curveto snaptopixel curveto % note control points are not snapped /Rt { % x y w h Rt - basic rectangle 4-2 roll Mt % bottom left hand corner dtransform round exch round exch idtransform dup 0 exch rlineto % to upper left exch 0 rlineto % to upper right neg 0 exch rlineto % to lower right closepath end % SAdict %%EndResource } if Level2 DPS { restore }if %%EndProlog %%BeginSetup GRinit true SA.001 setlinewidth %%EndSetup 84 108 Mt 84 738 Lt % longways lines 98 108 Mt 98 738 Lt 112 108 Mt 112 738 Lt 126 108 Mt 126 738 Lt 140 108 Mt 140 738 Lt 154 108 Mt 154 738 Lt 22 Appendix A: Spreadsheet Program Examples (31 Mar 92)

168 108 Mt 168 738 Lt 182 108 Mt 182 738 Lt 196 108 Mt 196 738 Lt 210 108 Mt 210 738 Lt 224 108 Mt 224 738 Lt 238 108 Mt 238 738 Lt 252 108 Mt 252 738 Lt 266 108 Mt 266 738 Lt 280 108 Mt 280 738 Lt 294 108 Mt 294 738 Lt 308 108 Mt 308 738 Lt 322 108 Mt 322 738 Lt 336 108 Mt 336 738 Lt 350 108 Mt 350 738 Lt 364 108 Mt 364 738 Lt 378 108 Mt 378 738 Lt 392 108 Mt 392 738 Lt 406 108 Mt 406 738 Lt 420 108 Mt 420 738 Lt 434 108 Mt 434 738 Lt 448 108 Mt 448 738 Lt 462 108 Mt 462 738 Lt 476 108 Mt 476 738 Lt 490 108 Mt 490 738 Lt 504 108 Mt 504 738 Lt 518 108 Mt 518 738 Lt 532 108 Mt 532 738 Lt 546 108 Mt 546 738 Lt 84 108 Mt 546 108 Lt % shortways lines 84 184 Mt 546 184 Lt 84 260 Mt 546 260 Lt 84 336 Mt 546 336 Lt 84 412 Mt 546 412 Lt 84 488 Mt 546 488 Lt 84 564 Mt 546 564 Lt 84 640 Mt 546 640 Lt 84 716 Mt 546 716 Lt 84 738 Mt 546 738 Lt stroke showpage 23

A stroke adjusted spreadsheet drawn with rectangles: %!PS-Adobe-3.0 %%Title: Spreadsheet drawn using Rt %%Creator: RH %%CreationDate: March 20, 1991 %%EndComments %%BeginProlog... the same prologue here...... and the same setup... %%EndSetup 84 108 462 630 Rt % longways rectangles 98 108 14 630 Rt 126 108 14 630 Rt 154 108 14 630 Rt 182 108 14 630 Rt 210 108 14 630 Rt 238 108 14 630 Rt 266 108 14 630 Rt 294 108 14 630 Rt 322 108 14 630 Rt 350 108 14 630 Rt 378 108 14 630 Rt 406 108 14 630 Rt 434 108 14 630 Rt 462 108 14 630 Rt 490 108 14 630 Rt 518 108 14 630 Rt 84 184 462 76 Rt % shortways rectangles 84 336 462 76 Rt 84 488 462 76 Rt 84 640 462 76 Rt stroke showpage 24 Appendix A: Spreadsheet Program Examples (31 Mar 92)

Appendix B: Changes Since Earlier Versions Changes since May 3, 1991 version Document was reformatted in the new document layout and minor editorial changes were made. 25

26 Appendix B: Changes Since Earlier Versions (31 Mar 92)

Index A, B automatic stroke adjustment absolute path operations 12 13, 17 absolute versus relative operators 17 emulating for Level 1 9 16 emulations 16 interface layer 16 Level 2 9 performance 17 18 rectangles 18 relative path operations 14 16 without losing Level 1 compatibility 19 C, D curveto 16 E, F emulated operators naming 11 emulations when to install 9 G, H, I, J GRinit 16 K known 9 L, M, N, O languagelevel 9, 10 P, Q path construction operators absolute 12 R rcurveto 16, 17 rectangles 18 rectstroke 18 restore 10 S, T, U, V save 10 setstrokeadjust emulation of 5 19 emulations samples 11 16 font handling mechanism 16 language level compatibility strategies 9 mapping user space path to device space pixels 8 spreadsheet with stroke adjustment 7 spreadsheet without stroke adjustment 6 VM saving 10 stroke adjustment device space and 5 9 W, X, Y, Z where 9, 10 27

28 Index (31 Mar 92)