-
-
Save chamons/ed446918b9f7f8a79e08 to your computer and use it in GitHub Desktop.
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
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