Skip to content

Commit

Permalink
started moving to macruby
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Oct 3, 2009
1 parent 3dce5e8 commit 5347072
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 31 deletions.
6 changes: 4 additions & 2 deletions README.rdoc
Expand Up @@ -13,8 +13,10 @@ http://www.slideshare.net/madrobby/textorize

Install the gem and binary by doing:

$ gem sources -a http://gems.github.com
$ sudo gem install madrobby-textorize
$ macgem sources -a http://gems.github.com
$ sudo gem install mattetti-textorize

(originally from madrobby-textorize)

This will install the textorize Ruby Gem, and the +textorize+ command
line tool.
Expand Down
3 changes: 2 additions & 1 deletion bin/textorize
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
#!/usr/bin/env macruby
require "optparse"
require 'rubygems'
require "textorize"

options = {}
Expand Down
1 change: 1 addition & 0 deletions lib/textorize.rb
@@ -1,3 +1,4 @@
framework 'cocoa'
$:.unshift File.dirname(__FILE__)

require "textorize/runner"
Expand Down
24 changes: 10 additions & 14 deletions lib/textorize/renderer.rb
@@ -1,14 +1,13 @@
require 'osx/cocoa'
framework 'cocoa'

module Textorize
class Renderer
include OSX

def initialize(window, string, options)
@text_view = NSTextView.alloc.initWithFrame([0,0,0,0])

set_attr_and_text options, string
window.setContentView @text_view
window.contentView = @text_view
@text_view.sizeToFit

window.display
Expand All @@ -32,25 +31,22 @@ def set_attr_and_text(options, string)
para.setLineSpacing(options[:lineheight])

attribs = NSMutableDictionary.alloc.init
attribs.setObject_forKey(NSFont.fontWithName_size(options[:font], options[:size]), NSFontAttributeName)
attribs.setObject_forKey(options[:kerning], NSKernAttributeName)
attribs.setObject_forKey(para, NSParagraphStyleAttributeName)
attribs.setObject_forKey(0, NSBaselineOffsetAttributeName)
attribs.setObject_forKey(options[:obliqueness], NSObliquenessAttributeName)
attribs.setObject(NSFont.fontWithName(options[:font], size: options[:size]), forKey: NSFontAttributeName)
attribs.setObject(options[:kerning], forKey: NSKernAttributeName)
attribs.setObject(para, forKey: NSParagraphStyleAttributeName)
attribs.setObject(0, forKey: NSBaselineOffsetAttributeName)
attribs.setObject(options[:obliqueness], forKey: NSObliquenessAttributeName)

@text_view.setTypingAttributes(attribs)
@text_view.lowerBaseline(nil)

@text_view.setString string
@text_view.string = string

color = (options[:color] || '0,0,0').split(',')
background = (options[:background] || '1,1,1').split(',')

@text_view.setTextColor(
NSColor.colorWithDeviceRed_green_blue_alpha(color[0], color[1], color[2], 1))

@text_view.setBackgroundColor(
NSColor.colorWithDeviceRed_green_blue_alpha(background[0], background[1], background[2], 1))
@text_view.setTextColor(NSColor.colorWithDeviceRed(color[0], green: color[1], blue: color[2], alpha:1))
@text_view.backgroundColor = NSColor.colorWithDeviceRed(background[0], green: background[1], blue: background[2], alpha:1)
end

end
Expand Down
11 changes: 4 additions & 7 deletions lib/textorize/runner.rb
@@ -1,30 +1,27 @@
require 'osx/cocoa'

module Textorize
class Runner

def initialize(string, output, options)
app = OSX::NSApplication.sharedApplication
app = NSApplication.sharedApplication

delegate = RunnerApplication.alloc.init
delegate.options = options
delegate.string = string
delegate.output = output

app.setDelegate delegate
app.delegate = delegate
app.run
end

end

class RunnerApplication < OSX::NSObject
include OSX
class RunnerApplication
attr_accessor :options
attr_accessor :string
attr_accessor :output

def initialize
@window = NSWindow.alloc.initWithContentRect_styleMask_backing_defer([-2000, -2000, 2000, 2000], NSBorderlessWindowMask, 2, 0)
@window = NSWindow.alloc.initWithContentRect([-2000, -2000, 2000, 2000], styleMask: NSBorderlessWindowMask, backing: 2, defer: 0)
end

def applicationDidFinishLaunching(notification)
Expand Down
5 changes: 2 additions & 3 deletions lib/textorize/saver.rb
@@ -1,15 +1,14 @@
module Textorize
class Saver
include OSX
attr_reader :png

def initialize(renderer)
bitmap = renderer.bitmap
@png = bitmap.representationUsingType_properties(NSPNGFileType, nil)
@png = bitmap.representationUsingType(NSPNGFileType, properties: nil)
end

def write_to_file(file)
@png.writeToFile_atomically(file, true)
@png.writeToFile(file, atomically: true)
end

end
Expand Down
8 changes: 4 additions & 4 deletions textorize.gemspec
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = "textorize"
s.version = "0.1.2"
s.version = "0.1.5"
s.date = "2009-09-27"
s.summary = "OS X subpixel antialiased PNG string renderer"
s.summary = "OS X subpixel antialiased PNG string renderer for MacRuby"
s.email = "thomas@fesch.at"
s.homepage = "http://github.com/madrobby/textorize"
s.homepage = "http://github.com/madrobby/textorize http://github.com/mattetti/textorize"
s.description = "Textorize is a OS X utility to render subpixel antialised strings into PNG files."
s.has_rdoc = false
s.require_paths = ['lib']
s.authors = ["Thomas Fuchs"]
s.authors = ["Thomas Fuchs", "Matt Aimonetti"]
s.files = ["Rakefile", "LICENSE", "bin/textorize", "lib/textorize", "lib/textorize/renderer.rb", "lib/textorize/runner.rb", "lib/textorize/saver.rb", "lib/textorize.rb", "test/test_runner.rb"]
s.test_files = Dir["test/test_*.rb"] unless $SAFE > 0
s.executables = ["textorize"]
Expand Down

0 comments on commit 5347072

Please sign in to comment.