Skip to content

Instantly share code, notes, and snippets.

@chamons
Created March 2, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/ed446918b9f7f8a79e08 to your computer and use it in GitHub Desktop.
Save chamons/ed446918b9f7f8a79e08 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.IO;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
namespace RFTTest
{
public static class RFTMonkeyPatch
{
static IntPtr appKit = Dlfcn.dlopen (@"/System/Library/Frameworks/AppKit.framework/AppKit", 0);
// NSStringAttributeKey.NSRtfTextDocumentType in XM 1.12
static NSString NSRTFTextDocumentType = Dlfcn.GetStringConstant (appKit, "NSRTFTextDocumentType");
static NSString NSDocumentTypeDocumentAttribute = Dlfcn.GetStringConstant (appKit, "NSDocumentTypeDocumentAttribute");
public static NSDictionary RFTConversionDictionary
{
get
{
return NSDictionary.FromObjectAndKey (NSDocumentTypeDocumentAttribute, NSRTFTextDocumentType);
}
}
}
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
public AppDelegate ()
{
}
public override void DidFinishLaunching (NSNotification notification)
{
mainWindowController = new MainWindowController ();
mainWindowController.Window.MakeKeyAndOrderFront (this);
var bytes = File.ReadAllBytes (@"/Users/donblas/Programming/Local/RFTTest/RFTTest/sample.rtf");
NSData data = NSData.FromArray (bytes);
NSDictionary d;
NSError e;
NSAttributedString s = new NSAttributedString (data, RFTMonkeyPatch.RFTConversionDictionary, out d, out e);
NSTextField b = new NSTextField (mainWindowController.Window.ContentView.Frame);
b.AttributedStringValue = s;
mainWindowController.Window.ContentView.AddSubview (b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment