Skip to content

Instantly share code, notes, and snippets.

if var font = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
font = NSFontManager.sharedFontManager().convertFont(font, toHaveTrait: .BoldFontMask)
// or ...
font = NSFontManager.sharedFontManager().convertFont(font, toNotHaveTrait: .BoldFontMask)
applyNewAttributes([NSFontAttributeName: font])
}
@IBAction func fontFaceChanged(sender: NSPopUpButton) {
let newIDX = sender.indexOfSelectedItem
if let currentFont = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
let newFaceName = fontFaceNames[newIDX]
if let newFont = NSFontManager.sharedFontManager().convertFont(currentFont, toFace: newFaceName) {
applyNewAttributes([NSFontAttributeName: newFont])
}
}
}
dynamic let fontFamilyNames = NSFontManager.sharedFontManager().availableFontFamilies
fontFamilyName!.bind("content", toObject: self, withKeyPath: "fontFamilyNames", options: nil)
@IBAction func fontFamilyChanged(sender: NSPopUpButton) {
let newIDX = sender.indexOfSelectedItem
if var font = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
font = NSFontManager.sharedFontManager().convertFont(font, toFamily: fontFamilyNames[newIDX])
applyNewAttributes([NSFontAttributeName: font])
}
func textViewDidChangeTypingAttributes(notification: NSNotification) {
if let font = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
if let faces = NSFontManager.sharedFontManager().availableMembersOfFontFamily(font.familyName) {
// faces is an array of arrays like this:
// [[Helvetica, Regular, 5, 0], [Helvetica-Light, Light, 3, 0], [Helvetica-Oblique, Oblique, 5, 1], [Helvetica-LightOblique, Light Oblique, 3, 1], [Helvetica-Bold, Bold, 9, 2], [Helvetica-BoldOblique, Bold Oblique, 9, 3]]
fontFacesLabels = faces.map({face in (face[1] as! String)})
}
}
}
class Document: NSDocument {
@IBAction func fontSizeChanged(sender: NSControl) {
var newSize = CGFloat(sender.floatValue)
if var font = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
font = NSFontManager.sharedFontManager().convertFont(font, toSize: newSize)
applyNewAttributes([NSFontAttributeName: font])
}
}
func applyNewAttributes(attributes: [String: AnyObject]) {
class Document: NSDocument {
@IBOutlet var fontSizeField: NSTextField?
dynamic var currentFontSize: CGFloat = 0
override func windowControllerDidLoadNib(aController: NSWindowController) {
super.windowControllerDidLoadNib(aController)
fontSizeField.bind("value",
toObject: self,
withKeyPath: "currentFontSize",
@keighl
keighl / photo_processor.rb
Created October 7, 2013 12:06
Example image manipulation worker from S3 using rmagick and aws-sdk-ruby
require 'RMagick'
class PhotoProcessor
def self.process(entry_id)
entry = Entry.find entry_id
raise "The photo for this entry has already been processed" if entry.image_processed?
@keighl
keighl / CBGameController.m
Last active September 1, 2018 17:24
SDWebImage in a UITableViewCell - cancel any download operation before reusing the cell. Otherwise, you might see previous images loading in before the correct one is finished downloading.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"MoveViewCell";
CBMoveView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell)
cell = [[CBMoveView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.move = (CBMove *)[self.moves objectAtIndex:indexPath.row];
@keighl
keighl / foooont.sh
Last active December 9, 2021 14:00
Rename a font to have the same Family/Fullname/Postscript name. This prevents IE from choking in @font-face
# FontForge command
fontforge -script 2ttf.pe ProprietaryFontCondensedBold.otf
# 2ttf.pe
# FontForge Script
# http://fontforge.org/scripting.html
#
# * Opens the font file
# * Sets the family/fullname/postscript name be the same as the filename (without ext)
@keighl
keighl / hotttness.coffee
Created March 28, 2013 20:32
jQuery plugin boilerplate
"use strict";
methods =
init: (options) ->
$(this).each ->
$self = $(@)
data = $self.data 'hotttness'
settings =