Last active
August 29, 2015 14:11
-
-
Save mnzk/480416196bba23151217 to your computer and use it in GitHub Desktop.
draw-text における文字回転の例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/gui) | |
(define font (make-font #:size 40 | |
#:size-in-pixels? #t | |
#:face "HGGyoshotai")) | |
(define font-size (send font get-point-size)) | |
(define font-size-half (/ font-size 2)) | |
(define rotate-text-hash '#hash(("ー" . #t))) | |
(define (rotate-txt? s) | |
(hash-ref rotate-text-hash s #f)) | |
(define (draw dc txt x y) | |
(for ((s (for/list ((c txt)) (string c))) | |
(i (in-naturals))) | |
(define yn (+ y (* font-size i))) | |
(if (not (rotate-txt? s)) | |
(send dc draw-text s x yn) | |
(let ((t (send dc get-transformation)) | |
(p0 (- font-size-half)) | |
(angle (/ pi -2))) | |
(send* dc | |
(set-origin (+ x font-size-half) | |
(+ yn font-size-half)) | |
(rotate angle) | |
(draw-text s p0 p0) | |
(set-transformation t)))))) | |
(define (main) | |
(define f (new frame% (label "TEST") | |
(width 200) | |
(height 500))) | |
(new canvas% (parent f) | |
(paint-callback | |
(lambda (_ dc) | |
(send dc set-font font) | |
(draw dc "ポール・グレアム" 50 50)))) | |
(send f show #t)) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment