Skip to content

Commit

Permalink
mac: Fix crash due to inaccessible system font
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Dec 22, 2017
1 parent bdd38b4 commit ab6e954
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
34 changes: 17 additions & 17 deletions SparkleShare/Mac/UserInterface/EventLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public EventLog ()
Bordered = false,
Editable = false,
Frame = new CGRect (
new CGPoint (60, ContentView.Frame.Height - 27),
new CGPoint (60, ContentView.Frame.Height - 31),
new CGSize (60, 20)),
StringValue = "",
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Font = NSFont.BoldSystemFontOfSize (12)
};


Expand All @@ -139,11 +139,11 @@ public EventLog ()
Bordered = false,
Editable = false,
Frame = new CGRect (
new CGPoint (190, ContentView.Frame.Height - 27),
new CGPoint (190, ContentView.Frame.Height - 31),
new CGSize (60, 20)
),
StringValue = "",
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Font = NSFont.BoldSystemFontOfSize (12)
};

this.popup_button = new NSPopUpButton () {
Expand Down Expand Up @@ -302,17 +302,17 @@ public void UpdateChooser (string [] folders)

this.popup_button.AddItem ("Summary");
this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem);
int row = 2;
foreach (string folder in folders) {

int row = 2;
foreach (string folder in folders) {
this.popup_button.AddItem (folder);
if (folder.Equals (Controller.SelectedFolder))
this.popup_button.SelectItem (row);
row++;
}

if (folder.Equals (Controller.SelectedFolder))
this.popup_button.SelectItem (row);

row++;
}

this.popup_button.AddItems (folders);

this.popup_button.Activated += delegate {
Expand All @@ -328,8 +328,8 @@ public void UpdateChooser (string [] folders)

public void UpdateContent (string html)
{
string pixmaps_path = "file://" + NSBundle.MainBundle.ResourcePath;
string pixmaps_path = "file://" + NSBundle.MainBundle.ResourcePath;

html = html.Replace ("<!-- $body-font-family -->", UserInterface.FontName);
html = html.Replace ("<!-- $day-entry-header-font-size -->", "13.6px");
html = html.Replace ("<!-- $body-font-size -->", "13.4px");
Expand All @@ -344,7 +344,7 @@ public void UpdateContent (string html)
html = html.Replace ("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png");
html = html.Replace ("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png");
html = html.Replace ("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png");

this.web_view = new WebView (new CGRect (0, 0, 481, 579), "", "") {
Frame = new CGRect (new CGPoint (0, 0), new CGSize (ContentView.Frame.Width, ContentView.Frame.Height - 39))
};
Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Mac/UserInterface/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void CreateNote ()
new CGPoint (85, ContentView.Frame.Height - 41),
new CGSize (320, 22)),
StringValue = SparkleShare.Controller.CurrentUser.Name,
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Font = NSFont.BoldSystemFontOfSize (12)
};

this.user_email_text_field = new NSTextField () {
Expand Down
36 changes: 16 additions & 20 deletions SparkleShare/Mac/UserInterface/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,15 @@ public void ShowPage (PageType type, string [] warnings)

AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Right);
AddressLabel.Frame = new CGRect (165, Frame.Height - 238, 160, 17);
AddressLabel.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);
AddressLabel.Font = NSFont.BoldSystemFontOfSize (12);

AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) {
Frame = new CGRect (330, Frame.Height - 240, 260, 17)
};

PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Right);
PathLabel.Frame = new CGRect (165, Frame.Height - 262, 160, 17);
PathLabel.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);

PathLabel.Font = NSFont.BoldSystemFontOfSize (12);

PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) {
Frame = new CGRect (330, Frame.Height - 264, 260, 17)
Expand Down Expand Up @@ -191,8 +190,8 @@ public void ShowPage (PageType type, string [] warnings)
Description = "";

AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) {
Frame = new CGRect (190, Frame.Height - 308, 160, 17),
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Frame = new CGRect (190, Frame.Height - 310, 160, 17),
Font = NSFont.BoldSystemFontOfSize (12)
};

AddressTextField = new NSTextField () {
Expand All @@ -205,8 +204,8 @@ public void ShowPage (PageType type, string [] warnings)
AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) {
Frame = new CGRect (190 + 196 + 16, Frame.Height - 308, 160, 17),
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Frame = new CGRect (190 + 196 + 16, Frame.Height - 310, 160, 17),
Font = NSFont.BoldSystemFontOfSize (12)
};

PathTextField = new NSTextField () {
Expand Down Expand Up @@ -256,9 +255,6 @@ public void ShowPage (PageType type, string [] warnings)
Editable = false
};

DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily (
UserInterface.FontName, NSFontTraitMask.Condensed, 0, 11);

TableView.AddColumn (IconColumn);
TableView.AddColumn (DescriptionColumn);

Expand Down Expand Up @@ -411,7 +407,7 @@ public void ShowPage (PageType type, string [] warnings)

string html = "<style>" +
"* {" +
" font-family: '" + UserInterface.FontName + "';" +
" font-family: -apple-system, '" + UserInterface.FontName + "';" +
" font-size: 12px; cursor: default;" +
"}" +
"body {" +
Expand Down Expand Up @@ -470,7 +466,7 @@ public void ShowPage (PageType type, string [] warnings)

ButtonCellProto = new NSButtonCell ();
ButtonCellProto.SetButtonType (NSButtonType.Radio);
ButtonCellProto.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);
ButtonCellProto.Font = NSFont.BoldSystemFontOfSize (12);

Matrix = new NSMatrix (new CGRect (202, Frame.Height - 256 - 128, 256, 256), NSMatrixMode.Radio,
ButtonCellProto, SparkleShare.Controller.FetcherAvailableStorageTypes.Count, 1);
Expand Down Expand Up @@ -529,8 +525,8 @@ public void ShowPage (PageType type, string [] warnings)
extra_pos_y = 20;

PasswordLabel = new SparkleLabel ("Password:", NSTextAlignment.Right) {
Frame = new CGRect (155, Frame.Height - 202 - extra_pos_y, 160, 17),
Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
Frame = new CGRect (155, Frame.Height - 204 - extra_pos_y, 160, 17),
Font = NSFont.BoldSystemFontOfSize (12)
};

PasswordTextField = new NSSecureTextField () {
Expand Down Expand Up @@ -694,14 +690,15 @@ public SparkleDataSource (float backing_scale_factor, List<Preset> presets)

NSTextFieldCell cell = new NSTextFieldCell ();

NSData name_data = NSData.FromString ("<font face='" + UserInterface.FontName + "'><b>" + preset.Name + "</b></font>");
NSData name_data = NSData.FromString (
"<font face='-apple-system, sans-serif' style='line-height: 140%'><b>" + preset.Name + "</b></font>");

NSDictionary name_dictionary = new NSDictionary();
NSAttributedString name_attributes = new NSAttributedString (
name_data, new NSUrl ("file://"), out name_dictionary);

NSData description_data = NSData.FromString (
"<small><font style='line-height: 150%' color='#aaa' face='" + UserInterface.FontName + "'>" + preset.Description + "</font></small>");
"<small><font style='line-height: 150%' color='#aaa' face='-apple-system, sans-serif'>" + preset.Description + "</font></small>");

NSDictionary description_dictionary = new NSDictionary();
NSAttributedString description_attributes = new NSAttributedString (
Expand All @@ -717,15 +714,14 @@ public SparkleDataSource (float backing_scale_factor, List<Preset> presets)
NSTextFieldCell selected_cell = new NSTextFieldCell ();

NSData selected_name_data = NSData.FromString (
"<font color='white' face='" + UserInterface.FontName +"'><b>" + preset.Name + "</b></font>");
"<font color='white' face='-apple-system, sans-serif' style='line-height: 140%'><b>" + preset.Name + "</b></font>");

NSDictionary selected_name_dictionary = new NSDictionary ();
NSAttributedString selected_name_attributes = new NSAttributedString (
selected_name_data, new NSUrl ("file://"), out selected_name_dictionary);

NSData selected_description_data = NSData.FromString (
"<small><font style='line-height: 150%' color='#9bbaeb' face='" + UserInterface.FontName + "'>" +
preset.Description + "</font></small>");
"<small><font style='line-height: 150%' color='#9bbaeb' face='-apple-system, sans-serif'>" + preset.Description + "</font></small>");

NSDictionary selected_description_dictionary = new NSDictionary ();
NSAttributedString selected_description_attributes = new NSAttributedString (
Expand Down
3 changes: 1 addition & 2 deletions SparkleShare/Mac/UserInterface/SetupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public SetupWindow ()

this.header_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
Frame = new CGRect (190, Frame.Height - 80, Frame.Width, 24),
Font = NSFontManager.SharedFontManager.FontWithFamily (
UserInterface.FontName, NSFontTraitMask.Bold, 0, 16)
Font = NSFont.BoldSystemFontOfSize (16)
};

this.description_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
Expand Down
1 change: 1 addition & 0 deletions SparkleShare/Mac/UserInterface/UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void Run (string [] args)
}


// To provide the right font in web views
public static string FontName {
get {
if (Environment.OSVersion.Version.Major < 14)
Expand Down

0 comments on commit ab6e954

Please sign in to comment.