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

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

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

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

Postscript Control Flow

Evaluation of postfix

A Short Introduction to PostScript

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

Package epsdice a scalable dice font

Drawing polygons: loops and arrays

Drawing curves automatically: procedures as arguments

Emulation of the setstrokeadjust Operator

WARNING for Autumn 2004:

Drawing polygons: loops and arrays

Emulation of the execform Operator

Joseph E. Coulson, Jr. Director. ~~/JVt~ (advisor's signature) Ball State University. Muncie, Indiana. February 29, Date of Graduation:

Lecture P5: Abstract Data Types

Exercises. Computer Tech Tom Browder Northwest Florida Linux User Group [nwflug.org]

Color Separation Conventions for PostScript Language Programs

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

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

Code Generation: Introduction

CSCI 136 Data Structures & Advanced Programming. Lecture 14 Fall 2018 Instructor: Bills

SOFTWARE ARCHITECTURE 4. TEXT FORMATTING SYSTEM

Lab 6: P.S. it s a stack Due 11:59 pm Monday, Mar 31, 2008

Package pst-barcode. v May 22, 2007

Stacks and Queues. !stacks!dynamic resizing!queues!generics!applications. Stacks and Queues

Font Switching Optimizations

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

P, A~ ALTERNATIVE SYNTAX FOR POSTSCRIPT: USER'S MANUAL. G. C. Ewing. Technical Report COSC 2/88

10 Using the PCFL Editor In this chapter

Stars around I PostScript straightaway

Mentor Graphics Predefined Packages

PostScript Internals Graphics II Spring 1999

USB direct printing_en.doc

CS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College

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

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

CALCA. I/A Series Software Advanced Calculator (CALCA) Block. Product Specifications INTEGRATED CONTROL INTELLIGENT AUTOMATION PSS 21S-3M8 B4

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

Coordinates and conditionals

Lab copy. Do not remove! Mathematics 152 Spring 1999 Notes on the course calculator. 1. The calculator VC. The web page

Functional Programming Languages (FPL)

Problem with Scanning an Infix Expression

The BCG Postscript Format. Louis-Pascal Tock. INRIA Rh^one-Alpes / VERIMAG. rue Lavoisier MONTBONNOT ST MARTIN FRANCE. October 1995.

Display PostScript System

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Display PostScript System

AMT Datasouth Fastmark. PAL TM Print and Program Language Reference Guide. P/N Rev. A1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSE 341 Section Handout #6 Cheat Sheet

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

CSC 533: Programming Languages. Spring 2015

Dissecting APT Sample Step by Step. Kārlis Podiņš, CERT.LV

PODi. May Personalized Print Markup Language. Application Notes. PODi: the Digital Printing Initiative

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Uniface Printing A White Paper by Debbra Mullen

Full file at

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

SaM. 1. Introduction. 2. Stack Machine

Vladimir Batagelj Department of mathematics, FMF, University of Ljubljana Jadranska 19, 1000 Ljubljana, Slovenia

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

A Short Introduction to PDF

Learning Forth. Developer Technical Support DTS. for Macintosh Open Firmware (Part I) 2/1/01 version 0.9 (part I) 1

Emulation of the makepattern and setpattern Operators

CD and DVD labels TIMTOWTDI. Introduction

Stack Abstract Data Type

Formal Languages and Automata Theory, SS Project (due Week 14)

Linear Data Structure

Lecture 2 FORTRAN Basics. Lubna Ahmed

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Downloaded from Chapter 2. Functions

Outline. Stacks. 1 Chapter 5: Stacks and Queues. favicon. CSI33 Data Structures

15-122: Principles of Imperative Computation, Fall 2015

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Loop Invariants. while!done do // what is true at every step // Update/iterate // maintain invariant od CPS

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Graphics. Graphics. Graphics

Arrays and Linked Lists

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

An informal tutorial on Joy 1

Variables. location where in memory is the information stored type what sort of information is stored in that memory

Lecture 12 ADTs and Stacks

Construction of Fourth-Order Central Differences

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Input and Expressions Chapter 3 Slides #4

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Pace University. Fundamental Concepts of CS121 1

Inf2C - Computer Systems Lecture 2 Data Representation

Virtual Machine Tutorial

Scheme Quick Reference

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

WYSE Academic Challenge 2002 Computer Science Test (Sectional) SOLUTION

Foxboro Evo Process Automation System

Transcription:

References Postscript Intro CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/ Postscript Language Reference, Adobe Postscript Language Tutorial and Cookbook, Adobe Adobe's Postscript web site» http://www.adobe.com/products/postscript/main.html Postscript resources, Jim Land» http://www.geocities.com/siliconvalley/5682/postscript.html Postscript resources, Doug Zongker (UW)» http://isotropic.org/uw/postscript/ First Guide to PostScript, Peter Weingartner» http://www.cs.indiana.edu/docproject/programming/postscript/postscript.html 24-Oct-2003 cse413-08-postscript 2005 University of Washington 1 24-Oct-2003 cse413-08-postscript 2005 University of Washington 2 What is Postscript? Hello World! in Ghostscript Page description language» device independent way of representing a 2D page» emphasis on scalable text, graphics presentation Simple programming language» stack oriented» interpreted Fundamental tool for 2D display images from Doug Zongker papers 24-Oct-2003 cse413-08-postscript 2005 University of Washington 3

Hello World! in GSView %!PS /Times-Roman findfont 50 scalefont setfont 72 720 moveto (Hello, World!) show showpage Page Description Language Graphics operators Text» any position, orientation, scale Geometric figures» straight and curved lines» filled spaces Sampled images» digitized photos, sketches, images 24-Oct-2003 cse413-08-postscript 2005 University of Washington 5 24-Oct-2003 cse413-08-postscript 2005 University of Washington 6 Imaging Model... Current page» independent of the device on which the image will actually be drawn - device independence» starts out empty, then painting operators are used to add opaque inking to the page Current path» set of points, lines and curves» path itself is not a mark on the page, it's just a path» inking is done by stroking and/or filling the path... Imaging Model Clipping path» boundary of the area that may be drawn upon» starts out matching the size of the default page area» may be set to any path 24-Oct-2003 cse413-08-postscript 2005 University of Washington 7 24-Oct-2003 cse413-08-postscript 2005 University of Washington 8

Coordinate Systems A Postscript program describes positions in terms of the user coordinate system or user space» independent of the printer's device coordinates» units are 1/72 inch, approximately one point Positions on a page are described as (x,y) pairs in a coordinate system imposed on the page» this is the device space Coordinates in user space are automatically translated to device space when the page is printed 24-Oct-2003 cse413-08-postscript 2005 University of Washington 9 /boxpath { newpath 0 0 moveto 0 72 rlineto 72 0 rlineto 0-72 rlineto closepath } def 36 700 translate boxpath 0 setgray fill 72-14.14 translate 45 rotate boxpath 2 setlinewidth 0.8 setgray stroke User Coordinates 24-Oct-2003 cse413-08-postscript 2005 University of Washington 10 Programming Language... A nice and relatively compact programming language Stack oriented» operand stack, dictionary stack Postfix notation» operators work on data from the stack»3+4 3 4 add» describe a bezier curve 72 720 moveto 82 750 92 690 102 720 curveto Data Types... Programming Language» includes reals, booleans, arrays, strings» procedures are executable arrays Flexible» dictionaries to store user defined objects» static and dynamic graphics capabilities Accessible source» Printable file is actually just a text program that can be edited with any text editor 24-Oct-2003 cse413-08-postscript 2005 University of Washington 11 24-Oct-2003 cse413-08-postscript 2005 University of Washington 12

Stack The stack is an area of memory where Postscript objects can be stored until consumed» last in, first out» push and pop are generally implicit. Numbers are always pushed as they are encountered. Operators can consume objects off the stack and push new objects onto the stack» several operators work directly on the stack to move the top few elements around Stack operation stack is empty push 5, then 27 2 objects on the stack GS>5 27 27 print stack 5 add top two objects, GS<2>add GS<1>pstack leaving the result on one object on stack 32 the stack GS<1> 24-Oct-2003 cse413-08-postscript 2005 University of Washington 13 24-Oct-2003 cse413-08-postscript 2005 University of Washington 14 Operators An operator is a word that causes the Postscript interpreter to carry out some action PS searches internal dictionaries to see if the word is an operator name» If listed, PS looks up the associated definition and executes it» Many predefined operators» Can define new operators as needed Defined Arithmetic Operators Predefined arithmetic operators include» add, div, idiv, mod, mul, sub» abs, neg» ceiling, floor, round, truncate» sqrt» atan, cos, sin, exp, ln, log» rand, srand, rrand 24-Oct-2003 cse413-08-postscript 2005 University of Washington 15 24-Oct-2003 cse413-08-postscript 2005 University of Washington 16

Stack operations Objects on the operand stack are consumed from the top: last in, first out» 6 + ( 3 / 8 )» 6 3 8 div add GS>6 3 8 GS<3>div GS<2>add GS<1>= 6.375 GS> 6 3 8 8 3 6.375 6 24-Oct-2003 cse413-08-postscript 2005 University of Washington 17 div add 6.375 Stack operations Postscript also allows you to rearrange and duplicate the top elements of the stack so that the needed operands are on top GS>4 5 % stack has two objects on it now GS<2>2 array % Create a 2-element array and leave reference on stack GS<3>dup % duplicate the reference GS<4>0 % we are going to set element 0 GS<5> % stack is now: 4 5 arr arr 0 GS<5>5-1 roll % stack is now: 5 arr arr 0 4 GS<5>put % stack is now: 5 arr GS<2>dup 1 % stack is now: 5 arr arr 1 GS<4>4-1 roll % stack is now arr arr 1 5 GS<4>put % stack is now: arr GS<1>pstack [4 5] GS<1> 24-Oct-2003 cse413-08-postscript 2005 University of Washington 18 dup, pop and roll dup» duplicate the top item on the stack. Useful for array references that are consumed by operations like put and get pop» remove top element from stack and discard roll» roll stack contents. Consumes two numbers from top of stack. Top number is how many times and what direction to rotate, second number is how many objects are to be rotated 7 8 9 3 1 roll 9 7 8 7 8 9 3-1 roll 8 9 7 24-Oct-2003 cse413-08-postscript 2005 University of Washington 19 Operand Stack Operators pop exch dup, copy, index roll clear, count mark, cleartomark, counttomark 24-Oct-2003 cse413-08-postscript 2005 University of Washington 20

Interactive Operand Stack Operators ==» pops an object from the stack and produces a text representation of the object as best it can pstack» prints the contents of the stack, but does not remove anything from the stack Arrays Postscript arrays are 1-dimensional collections of objects» indexed from 0» objects can be of any type - integers, strings, other arrays, dictionaries, etc Similar to Object arrays in Java, although Postscript arrays can hold primitive elements as well as reference elements 24-Oct-2003 cse413-08-postscript 2005 University of Washington 21 24-Oct-2003 cse413-08-postscript 2005 University of Washington 22 Creating an array An array can be created by directly specifying the elements enclosed in square brackets» [ 16 (twelve) 8] creates a 3-element array number 16, string "twelve", number 8» [ (sum) 6 14 add] creates a 2-element array string "sum", number 20 note that the operator add is executed An array can be created with the array operator» 3 array creates a 3-element array of all null There are now two array references on the stack. Array example GS>[1 2 3] GS<1>pstack [1 2 3] GS<1>3 array [null null null] [1 2 3] GS<2>dup 0 (Hi!) put [(Hi!) null null] [1 2 3] GS<2>exch dup 2 333 put [1 2 333] [(Hi!) null null] GS<2> create an array create an empty array set element 0 to string set element 2 to 333 24-Oct-2003 cse413-08-postscript 2005 University of Washington 23 24-Oct-2003 cse413-08-postscript 2005 University of Washington 24

Array bracket operators [» put a mark on the stack. The following elements are going to be scooped up in an array ]» create an array containing all elements back to the topmost mark. The array is created on the heap in virtual memory, and an array reference is left on the stack example: [ 1 1 1 add] 2-element array : [1 2] Array operators put and get array index any put» puts any at index of array» removes all three objects from the stack array index get» gets the object at index of array» removes both objects from the stack and returns the indexed element on the top of the stack Note that if you want to use the array reference again you need to dup it or name it 24-Oct-2003 cse413-08-postscript 2005 University of Washington 25 24-Oct-2003 cse413-08-postscript 2005 University of Washington 26 Array operators array, [, ] length get, put, getinterval, putinterval astore, aload, copy forall GS>0 [ 1 2 3] {add} forall == 6 GS> 24-Oct-2003 cse413-08-postscript 2005 University of Washington 27