- Forward


Described Static Visual Content
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Simple Geometric Shapes
Back SMYC Forward
  • 0-Dimensional
    • Points
  • 1-Dimensional
    • Lines
    • Curves
  • 2-Dimensional
    • Rectangles and Rounded Rectangles
    • Polygons
    • Ellipses
"Quick Start"
Back SMYC Forward
javaexamples/visual/statik/described/RandomRectangleCanvas.java
 
Encapsulating Points
Back SMYC Forward
  • Basics:
    • A point is defined by its x (i.e., horizontal) andy (i.e., vertical) coordinates
    • Point2D
  • An Example:
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: point)
 
Encapsulating Line Segments
Back SMYC Forward
  • What You Know:
    • A line is often defined as the set of pairs, <x,y>, that satisfy: \(y = A x + B\) for given values of A and B
  • Shortcomings:
    • Can't represent vertical lines
    • We are interested in line segments not lines
    • Not very intuitive
Encapsulating Line Segments (cont.)
Back SMYC Forward
  • Parametric Form:
    • \(x(u) = u^0 a_x + u^1 b_x\)
    • \(y(u) = u^0 a_y + u^1 b_y\)
  • Constraints:
    • We want \((x(0),y(0)) = p\) (one endpoint)
    • We want \((x(1),y(1)) = q\) (the other endpoint)
  • Implications:
    • \(a_x = p_x\) and \(a_y = p_y\)
    • \(b_x = q_x - p_x\) and \(b_y = q_y - p_y\)
Encapsulating Line Segments (cont.)
Back SMYC Forward
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: line)
 
Encapsulating Line Segments (cont.)
Back SMYC Forward
An Observation before Continuing

\(x(u) = p_x + u q_x - u p_x = (1 - u) p_x + u q_x\)

\(y(u) = p_y + u q_y - u p_y = (1 - u) p_y + u q_y\)

Encapsulating Quadratic Bezier Curves
Back SMYC Forward
  • Basics:
    • \(x(u) = (1 - u)^2 p_x + 2(1-u)u r_x + u^2 q_x\)
    • \(y(u) = (1 - u)^2 p_y + 2(1-u)u r_y + u^2 q_y\)
    • QuadCurve2D uses the end points and a control point
    • curve-quadratic
  • An Example:
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: quadcurve)
 
Encapsulating Cubic Curves
Back SMYC Forward
  • Basics:
    • \(x(u) = (1 - u)^3 p_x + 3(1-u)^2u r_x + 2(1-u)^2u s_x + u^3 q_x\)
    • \(y(u) = (1 - u)^3 p_y + 3(1-u)^2u r_y + 2(1-u)^2u s_y + u^3 q_y\)
    • CubicCurve2D uses the end points and two control points
    • curve-cubic
  • An Example:
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: cubiccurve)
 
Encapsulating Rectangles
Back SMYC Forward
  • Basics:
    • Rectangles are typically defined using one corner, a width, and a height
    • Rectangle2D
  • An Example:
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: rectangle)
 
Encapsulating Ellipses and Arcs
Back SMYC Forward
  • Basics:
    • Often defined using a center, major diameter, and minor diameter
    • Ellipse2D uses the bounding rectangle
    • ellipse
  • An Example:
javaexamples/visual/statik/described/SimpleShapeCanvas.java (Fragment: arc)
 
Convexity of Closed 2-Dimensional Shapes
Back SMYC Forward
convex nonconvex
Glyphs
Back SMYC Forward
  • Glyph:
    • A shape that represents one or more characters
  • Font:
    • A set of glyphs
Glyphs (cont.)
Back SMYC Forward

f and i as two glyphs and as a ligature

ligature
Glyphs (cont.)
Back SMYC Forward
  • Important Terms:
    • Width
    • Left-Side Bearing (LSB)
    • Right-Side Bearing (RSB)
    • Advance (the sum of the above)
  • Sign:
    • Width is always positive
    • LSB and RSB can be negative
Glyphs (cont.)
Back SMYC Forward

The RSB is positive for A and negative for f

glyph-advance
Glyphs (cont.)
Back SMYC Forward

Kerning - The Use of Different Bearings for Differnt Glyphs

kerning
Glyphs (cont.)
Back SMYC Forward
  • More Important Terms:
    • Ascent
    • Descent
    • Leading (pronounced led-ing)
    • Height (the sum of the above)
  • Note:
    • These are properties of the font, not individual glyphs
Glyphs (cont.)
Back SMYC Forward

Line Metrics

fontmetrics
Glyphs (cont.)
Back SMYC Forward
  • FontRenderContext
    • Keeps information about fonts
  • Font
    • Can create a GlyphVector
  • LineMetrics
    • Keeps information about font and line heights
Glyphs (cont.)
Back SMYC Forward

Glyphs as Shapes

javaexamples/visual/statik/described/GlyphCanvas.java
 
Glyphs (cont.)
Back SMYC Forward

Font Metrics

javaexamples/visual/statik/described/GlyphMetricsCanvas.java
 
Glyphs (cont.)
Back SMYC Forward

Bounding Rectangle

javaexamples/visual/statik/described/CenteredGlyphCanvas.java
 
Glyphs (cont.)
Back SMYC Forward
  • An Observation:
    • It is sometimes inconvenient to create the Shape objects and render them
  • Convenience Methods:
    • Graphics2D.drawGlyphVector(java.awt.font.GlyphVector, float, float)
    • Graphics2D.drawString(java.lang.String, float, float)
    • Graphics2D.drawString(java.text.AttributedCharacterIterator, float, float)
Glyphs (cont.)
Back SMYC Forward

Using Convenience Methods

javaexamples/visual/statik/described/AttributedStringCanvas.java
 
Complicated Geometric Shapes
Back SMYC Forward
  • Describing:
    • Use a sequence of "move to", "line to", "quadratic-curve to", and/or "cubic-curve to" segments
  • In Java:
    • Path2D
    • PathIterator
Complicated Geometric Shapes (cont.)
Back SMYC Forward

An Example

javaexamples/visual/statik/described/BoringBuzzy.java (Fragment: body1)
 
Constructive Area Geometry
Back SMYC Forward
  • Defined:
    • The process of performing set-theoretic operations (e.g., union, intersection, difference, symmetric difference) on two-dimensional shapes
  • In Java:
    • The Area class
Constructive Area Geometry (cont.)
Back SMYC Forward

An Example

javaexamples/visual/statik/described/ConstructiveAreaGeometryCanvas.java
 
Transforms
Back SMYC Forward
  • An Observation:
    • In many situations, we don't want to transform the coordinate space, we instead want to transform the content itself
  • In Java:
    • getTranslateInstance(double, double)
    • getScaleInstance(double, double)
    • getRotateInstance(double)
Transforms (cont.)
Back SMYC Forward

Translation

translation
Transforms (cont.)
Back SMYC Forward

Two Scalings

scaling
Transforms (cont.)
Back SMYC Forward

Reflection

reflection
Transforms (cont.)
Back SMYC Forward

Rotation

rotation
Transforms (cont.)
Back SMYC Forward

An Example

javaexamples/visual/statik/described/SpiralGlyphCanvas.java
 
Rendering Described Content
Back SMYC Forward
  • Rendering in General:
    • Coordinate Conversion, Clipping and Composition
  • Unique Steps:
    • rendering_vector
Rendering Described Content (cont.)
Back SMYC Forward

Stroke Joins

stroke_joins
Rendering Described Content (cont.)
Back SMYC Forward

Stroke Caps

stroke_caps
Rendering Described Content (cont.)
Back SMYC Forward
  • Filling in General:
    • filling
  • Filling in Java:
    • Paint interface
    • Color object
    • GradientPaint object
    • TexturePaint object
Rendering Described Content (cont.)
Back SMYC Forward

An Example

javaexamples/visual/statik/described/RenderingExampleCanvas.java
 
Design of a Described Static Visual Content System
Back SMYC Forward
Requirements
  1. Support the addition of described static visual content
  2. Support the removal of described static visual content
  3. Support \(z\)-ordering of described static visual content
  4. Support the transformation of described static visual content
  5. Support the rendering of described static visual content
Design of a Described Static Visual Content System
Back SMYC Forward
  • A Problem:
    • Shapes do not contain all of the information required for rendering (i.e., they do not contain information related to stroking and filling)
    • This information must be stored elsewhere and the GUI component doing the rendering must understand how to put everything together
  • Overcoming this Problem:
    • There are several possible designs
Design of a Described System (cont.)
Back SMYC Forward

Two Designs

attributedshape decoratedshape
Design of a Described System (cont.)
Back SMYC Forward

A Better Design

TransformableContent_described
Design of a Described System (cont.)
Back SMYC Forward
TransformableContent
javaexamples/visual/statik/described/TransformableContent.java
 
Design of a Described System (cont.)
Back SMYC Forward
Content
javaexamples/visual/statik/described/Content.java (Fragment: skeleton)
 
javaexamples/visual/statik/described/Content.java (Fragment: getters)
 
javaexamples/visual/statik/described/Content.java (Fragment: setters)
 
javaexamples/visual/statik/described/Content.java (Fragment: transform)
 
javaexamples/visual/statik/described/Content.java (Fragment: bounds)
 
javaexamples/visual/statik/described/Content.java (Fragment: render)
 
There's Always More to Learn
Back -