textorize-mr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/Rakefile +16 -0
- data/bin/textorize +53 -0
- data/lib/textorize.rb +6 -0
- data/lib/textorize/renderer.rb +53 -0
- data/lib/textorize/runner.rb +29 -0
- data/lib/textorize/saver.rb +15 -0
- data/test/test_runner.rb +18 -0
- metadata +63 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 Thomas Fuchs
|
2
|
+
http://script.aculo.us/thomas
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.test_files = FileList["test/test_*.rb"]
|
10
|
+
t.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::GemPackageTask.new(eval(IO.read(File.join(File.dirname(__FILE__), "textorize.gemspec")))) do |pkg|
|
14
|
+
pkg.need_zip = true
|
15
|
+
pkg.need_tar = true
|
16
|
+
end
|
data/bin/textorize
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env macruby
|
2
|
+
require "optparse"
|
3
|
+
require 'rubygems'
|
4
|
+
require "textorize"
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #$0 [options] string"
|
9
|
+
|
10
|
+
opts.on('-f', '--font=[FONT]', String, 'Font name') do |v|
|
11
|
+
options[:font] = v
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on('-s', '--size=[SIZE]', Float, 'Font size in point') do |v|
|
15
|
+
options[:size] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-l', '--lineheight=[HEIGHT]', Float, 'Line height in point') do |v|
|
19
|
+
options[:lineheight] = v
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-o', '--output=[FILENAME]', String, 'Specify filename for saving') do |v|
|
23
|
+
options[:output] = v
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-b', '--obliqueness=[ANGLE]', Float, 'Slant angle') do |v|
|
27
|
+
options[:obliqueness] = v
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-c', '--color=[COLOR]', String, 'Render text in specific color') do |v|
|
31
|
+
options[:color] = v
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-b', '--background=[COLOR]', String, 'Render background in specific color') do |v|
|
35
|
+
options[:background] = v
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on_tail('-h', '--help', 'Display this message and exit') do
|
39
|
+
puts opts
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
end.parse!
|
43
|
+
|
44
|
+
options[:font] ||= 'Arial'
|
45
|
+
options[:size] ||= 28.0
|
46
|
+
options[:kerning] ||= 0
|
47
|
+
options[:lineheight] ||= options[:size]
|
48
|
+
options[:output] ||= 'output.png'
|
49
|
+
options[:strings] = ARGV.first || 'MacRuby'
|
50
|
+
options[:width] ||= 250
|
51
|
+
options[:obliqueness] ||= 0
|
52
|
+
|
53
|
+
renderer = Textorize::Runner.new(options[:strings], options[:output], options)
|
data/lib/textorize.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
framework 'cocoa'
|
2
|
+
|
3
|
+
module Textorize
|
4
|
+
class Renderer
|
5
|
+
|
6
|
+
def initialize(window, string, options)
|
7
|
+
@text_view = NSTextView.alloc.initWithFrame([0,0,0,0])
|
8
|
+
|
9
|
+
set_attr_and_text(options, string)
|
10
|
+
window.contentView = @text_view
|
11
|
+
@text_view.sizeToFit
|
12
|
+
|
13
|
+
window.display
|
14
|
+
window.orderFrontRegardless
|
15
|
+
end
|
16
|
+
|
17
|
+
def bitmap
|
18
|
+
@text_view.lockFocus
|
19
|
+
bitmap = NSBitmapImageRep.alloc.initWithFocusedViewRect(@text_view.bounds)
|
20
|
+
@text_view.unlockFocus
|
21
|
+
bitmap
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def set_attr_and_text(options, string)
|
27
|
+
@text_view.horizontallyResizable = true
|
28
|
+
@text_view.useAllLigatures(nil)
|
29
|
+
|
30
|
+
para = NSMutableParagraphStyle.alloc.init
|
31
|
+
para.lineSpacing = options[:lineheight]
|
32
|
+
|
33
|
+
@text_view.typingAttributes = {
|
34
|
+
NSFontAttributeName => NSFont.fontWithName(options[:font], size: options[:size]),
|
35
|
+
NSKernAttributeName => options[:kerning],
|
36
|
+
NSParagraphStyleAttributeName => para,
|
37
|
+
NSBaselineOffsetAttributeName => 0,
|
38
|
+
NSObliquenessAttributeName => options[:obliqueness]
|
39
|
+
}
|
40
|
+
|
41
|
+
@text_view.lowerBaseline(nil)
|
42
|
+
|
43
|
+
@text_view.string = string
|
44
|
+
color = (options[:color] || '0,0,0').split(',')
|
45
|
+
background = (options[:background] || '1,1,1').split(',')
|
46
|
+
|
47
|
+
@text_view.textColor = NSColor.colorWithDeviceRed(color[0], green: color[1], blue: color[2], alpha:1)
|
48
|
+
@text_view.backgroundColor = NSColor.colorWithDeviceRed(background[0], green: background[1], blue: background[2], alpha:1)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Textorize
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
def initialize(string, output, options)
|
5
|
+
app = NSApplication.sharedApplication
|
6
|
+
app.delegate = RunnerApplication.new(string, output, options)
|
7
|
+
app.run
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class RunnerApplication
|
13
|
+
|
14
|
+
def initialize(string, output, options)
|
15
|
+
@window = NSWindow.alloc.initWithContentRect([-2000, -2000, 2000, 2000], styleMask: NSBorderlessWindowMask, backing: 2, defer: 0)
|
16
|
+
@string = string
|
17
|
+
@output = output
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def applicationDidFinishLaunching(notification)
|
22
|
+
renderer = Renderer.new(@window, @string, @options)
|
23
|
+
Saver.new(renderer).write_to_file(@output)
|
24
|
+
NSApplication.sharedApplication.terminate(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Textorize
|
2
|
+
class Saver
|
3
|
+
attr_reader :png
|
4
|
+
|
5
|
+
def initialize(renderer)
|
6
|
+
bitmap = renderer.bitmap
|
7
|
+
@png = bitmap.representationUsingType(NSPNGFileType, properties: nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
def write_to_file(file)
|
11
|
+
@png.writeToFile(file, atomically: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/test/test_runner.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w".. lib textorize")
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class RunnerTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_runner
|
7
|
+
options = {}
|
8
|
+
options[:font] ||= 'Arial'
|
9
|
+
options[:size] ||= 28.0
|
10
|
+
options[:kerning] ||= 0
|
11
|
+
options[:lineheight] ||= options[:size]
|
12
|
+
options[:width] ||= 250
|
13
|
+
options[:obliqueness] ||= 0
|
14
|
+
|
15
|
+
Textorize::Runner.new 'Hallo!', 'output.png', options
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: textorize-mr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Fuchs
|
8
|
+
- Matt Aimonetti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-09-27 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Textorize is a OS X utility to render subpixel antialised strings into PNG files.
|
18
|
+
email: thomas@fesch.at
|
19
|
+
executables:
|
20
|
+
- textorize
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- Rakefile
|
27
|
+
- LICENSE
|
28
|
+
- bin/textorize
|
29
|
+
- lib/textorize/renderer.rb
|
30
|
+
- lib/textorize/runner.rb
|
31
|
+
- lib/textorize/saver.rb
|
32
|
+
- lib/textorize.rb
|
33
|
+
- test/test_runner.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/mattetti/textorize
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: OS X subpixel antialiased PNG string renderer for MacRuby
|
62
|
+
test_files:
|
63
|
+
- test/test_runner.rb
|