 import SwiftyHaru
 
-let document = SwiftyHaru.PDFDocument()
-let page = document.addPage()
-
-page.draw { context in
-    let rectangle = Path().appendingRectangle(x: 50, y: 50, width: page.width - 100, height: page.height - 110)
-    context.stroke(rectangle)
-}
-
 func drawLine(in context: DrawingContext, x: Float, y: Float, label: String) {
-    let line = Path().moving(toX: x, y: y - 15).appendingLine(toX: x + 220, y: y - 15)
+    
+    let line = Path()
+        .moving(toX: x, y: y - 15)
+        .appendingLine(toX: x + 220, y: y - 15)
+    
     context.stroke(line)
+    context.fontSize = 10
+    context.show(text: label, atPosition: Point(x: x, y: y - 10))
 }
 
 func drawLine2(in context: DrawingContext, x: Float, y: Float, label: String) {
     let line = Path().moving(toX: x + 30, y: y - 25).appendingLine(toX: x + 160, y: y - 25)
     context.stroke(line)
+    context.show(text: label, atPosition: Point(x: x, y: y))
 }
 
 func constructRect(in context: DrawingContext, x: Float, y: Float, label: String) -> Path {
+    context.show(text: label, atPosition: Point(x: x, y: y - 10))
     return Path().appendingRectangle(x: x, y: y - 40, width: 220, height: 25)
 }
 
+let document = SwiftyHaru.PDFDocument()
+let page = document.addPage()
+let pageTitle = "Line Example"
+
+// Print the lines of the page.
+page.draw { context in
+    
+    let rectangle = Path()
+        .appendingRectangle(x: 30,
+                            y: 50,
+                            width: page.width - 60,
+                            height: page.height - 110)
+    context.stroke(rectangle)
+}
+
+// Print the title of the page (with positioning center).
+page.draw { context in
+    
+    context.fontSize = 24
+    
+    let textWidth = context.textWidth(for: pageTitle)
+    let position = Point(x: (page.width - textWidth) / 2,
+                         y: page.height - 50)
+    
+    context.show(text: pageTitle, atPosition: position)
+}
+
+// Draw various widths of lines.
 page.draw { context in
     
     context.lineWidth = 0

    
    context.stroke(Path().moving(to: point).appendingCurve(controlPoint1: point1, endPoint: point2))
    
    point = point + Vector(x: 0, y: -150)
    point1 = point1 + Vector(x: 0, y: -160)
    point2 = point2 + Vector(x: 10, y: -130)
    
    context.dashStyle = DashStyle(pattern: [3])!
    context.lineWidth = 0.5
    

    
    context.stroke(Path().moving(to: point).appendingCurve(controlPoint2: point1, endPoint: point2))
    
    // Curve example (appendingCurve(controlPoint1:endPoint))
    point = point + Vector(x: 0, y: -150)
    point1 = point1 + Vector(x: 0, y: -150)
    point2 = point2 + Vector(x: 0, y: -150)
    
    context.show(text: "appendCurve(controlPoint1:endPoint)",
                 atPosition: Point(x: 300, y: 400))
    
    currentPoint = Point(x: point.x + 5, y: point.y - 5)
    context.show(text: "currentPosition", atPosition: currentPoint)
    currentPoint = currentPoint + (point1 - point)
    context.show(text: "controlPoint1", atPosition: currentPoint)
    currentPoint = currentPoint + (point2 - point1)
    context.show(text: "endPoint", atPosition: currentPoint)
    
    context.dashStyle = DashStyle(pattern: [3])!
    context.lineWidth = 0.5
    
