challenge Hello, world! PDF版

Hello, world!シリーズの続編です。 「Hello, world!」となるべく大きく書かれた1ページのPDFを出力してください。

Posted feedbacks - Common Lisp

xycairo (xyzzy の cairo バインディング) を使って書きました。

cl-cairo2 を使えばもう少しシンプルに書けると思います
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
(require :cairo)
(use-package :cairo)
(use-package :cairo.ext)

(defun hello-pdf (width height text)
  (flet ((calc-font-size (cr x text)
           (with-cairo-save (cr)
             (cairo-set-font-size cr 100.0)
             (* 100.0 (/ x (cdr (assoc :width (cairo-text-extents-alist cr text))))))))
    (with-cairo-surface (surface (cairo-pdf-surface-create "hello.pdf" width height))
      (with-cairo (cr (cairo-create surface))
        (cairo-set-source-rgb cr 0 0 0) ; black
        (cairo-set-font-size cr (calc-font-size cr width text))
        (cairo-move-to cr 0 (/ height 2))
        (cairo-show-text cr text)))))

(hello-pdf 291 210 "Hello, world!")

Index

Feed

Other

Link

Pathtraq

loading...