aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-06-21 05:04:24 +0000
committerPo Lu2022-06-21 05:04:47 +0000
commit8cf3c3203b07b781ed34627fce0283d2b1b03fd7 (patch)
tree55f62cdd2e93b42654a4561cf2c96be323443460 /src
parentc175984e2c909979da915ac46b0c92de67f4b249 (diff)
downloademacs-8cf3c3203b07b781ed34627fce0283d2b1b03fd7.tar.gz
emacs-8cf3c3203b07b781ed34627fce0283d2b1b03fd7.zip
Allow toggling antialiasing inside the Haiku font dialog
* src/haiku_support.cc (struct font_selection_dialog_message): New field `disable_antialias'. (MessageReceived): Handle new message SET_DISABLE_ANTIALIASING. (class DualLayoutView): Rename to `TripleLayoutView'. (class TripleLayoutView): Rename from `DualLayoutView'. (MinSize): Update computations for three views. (class EmacsFontSelectionDialog, UpdatePreview) (EmacsFontSelectionDialog): Add an antialiasing checkbox to control antialiasing. (be_select_font): New arguments `initial_antialias' and `disable_antialias'. * src/haiku_support.h: Update prototypes. * src/haikufont.c (haikufont_pattern_from_object): Set FSPEC_ANTIALIAS. (Fx_select_font): Update accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/haiku_support.cc105
-rw-r--r--src/haiku_support.h3
-rw-r--r--src/haikufont.c26
3 files changed, 100 insertions, 34 deletions
diff --git a/src/haiku_support.cc b/src/haiku_support.cc
index e09f886990e..7819cef5683 100644
--- a/src/haiku_support.cc
+++ b/src/haiku_support.cc
@@ -92,22 +92,23 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
92/* Some messages that Emacs sends to itself. */ 92/* Some messages that Emacs sends to itself. */
93enum 93enum
94 { 94 {
95 SCROLL_BAR_UPDATE = 3000, 95 SCROLL_BAR_UPDATE = 3000,
96 WAIT_FOR_RELEASE = 3001, 96 WAIT_FOR_RELEASE = 3001,
97 RELEASE_NOW = 3002, 97 RELEASE_NOW = 3002,
98 CANCEL_DROP = 3003, 98 CANCEL_DROP = 3003,
99 SHOW_MENU_BAR = 3004, 99 SHOW_MENU_BAR = 3004,
100 BE_MENU_BAR_OPEN = 3005, 100 BE_MENU_BAR_OPEN = 3005,
101 QUIT_APPLICATION = 3006, 101 QUIT_APPLICATION = 3006,
102 REPLAY_MENU_BAR = 3007, 102 REPLAY_MENU_BAR = 3007,
103 FONT_FAMILY_SELECTED = 3008, 103 FONT_FAMILY_SELECTED = 3008,
104 FONT_STYLE_SELECTED = 3009, 104 FONT_STYLE_SELECTED = 3009,
105 FILE_PANEL_SELECTION = 3010, 105 FILE_PANEL_SELECTION = 3010,
106 QUIT_PREVIEW_DIALOG = 3011, 106 QUIT_PREVIEW_DIALOG = 3011,
107 SET_FONT_INDICES = 3012, 107 SET_FONT_INDICES = 3012,
108 SET_PREVIEW_DIALOG = 3013, 108 SET_PREVIEW_DIALOG = 3013,
109 UPDATE_PREVIEW_DIALOG = 3014, 109 UPDATE_PREVIEW_DIALOG = 3014,
110 SEND_MOVE_FRAME_EVENT = 3015, 110 SEND_MOVE_FRAME_EVENT = 3015,
111 SET_DISABLE_ANTIALIASING = 3016,
111 }; 112 };
112 113
113/* X11 keysyms that we use. */ 114/* X11 keysyms that we use. */
@@ -146,6 +147,9 @@ struct font_selection_dialog_message
146 /* Whether or not a size was explicitly specified. */ 147 /* Whether or not a size was explicitly specified. */
147 bool_bf size_specified : 1; 148 bool_bf size_specified : 1;
148 149
150 /* Whether or not antialiasing should be disabled. */
151 bool_bf disable_antialias : 1;
152
149 /* The index of the selected font family. */ 153 /* The index of the selected font family. */
150 int family_idx; 154 int family_idx;
151 155
@@ -2574,6 +2578,9 @@ class EmacsFontPreviewDialog : public BWindow
2574 current_font = new BFont; 2578 current_font = new BFont;
2575 current_font->SetFamilyAndStyle (name, sname); 2579 current_font->SetFamilyAndStyle (name, sname);
2576 2580
2581 if (message->GetBool ("emacs:disable_antialiasing", false))
2582 current_font->SetFlags (B_DISABLE_ANTIALIASING);
2583
2577 if (size_name && strlen (size_name)) 2584 if (size_name && strlen (size_name))
2578 { 2585 {
2579 size = atoi (size_name); 2586 size = atoi (size_name);
@@ -2615,26 +2622,32 @@ public:
2615 } 2622 }
2616}; 2623};
2617 2624
2618class DualLayoutView : public BView 2625class TripleLayoutView : public BView
2619{ 2626{
2620 BScrollView *view_1; 2627 BScrollView *view_1;
2621 BView *view_2; 2628 BView *view_2, *view_3;
2622 2629
2623 void 2630 void
2624 FrameResized (float new_width, float new_height) 2631 FrameResized (float new_width, float new_height)
2625 { 2632 {
2626 BRect frame; 2633 BRect frame;
2627 float width, height; 2634 float width, height, height_1, width_1;
2635 float basic_height;
2628 2636
2629 frame = Frame (); 2637 frame = Frame ();
2630 2638
2631 view_2->GetPreferredSize (&width, &height); 2639 view_2->GetPreferredSize (&width, &height);
2640 view_3->GetPreferredSize (&width_1, &height_1);
2641
2642 basic_height = height + height_1;
2632 2643
2633 view_1->MoveTo (0, 0); 2644 view_1->MoveTo (0, 0);
2634 view_1->ResizeTo (BE_RECT_WIDTH (frame), 2645 view_1->ResizeTo (BE_RECT_WIDTH (frame),
2635 BE_RECT_HEIGHT (frame) - height); 2646 BE_RECT_HEIGHT (frame) - basic_height);
2636 view_2->MoveTo (2, BE_RECT_HEIGHT (frame) - height); 2647 view_2->MoveTo (2, BE_RECT_HEIGHT (frame) - basic_height);
2637 view_2->ResizeTo (BE_RECT_WIDTH (frame) - 4, height); 2648 view_2->ResizeTo (BE_RECT_WIDTH (frame) - 4, height);
2649 view_3->MoveTo (2, BE_RECT_HEIGHT (frame) - height_1);
2650 view_3->ResizeTo (BE_RECT_WIDTH (frame) - 4, height_1);
2638 2651
2639 BView::FrameResized (new_width, new_height); 2652 BView::FrameResized (new_width, new_height);
2640 } 2653 }
@@ -2644,19 +2657,24 @@ class DualLayoutView : public BView
2644 MinSize (void) 2657 MinSize (void)
2645 { 2658 {
2646 float width, height; 2659 float width, height;
2660 float width_1, height_1;
2647 BSize size_1; 2661 BSize size_1;
2648 2662
2649 size_1 = view_1->MinSize (); 2663 size_1 = view_1->MinSize ();
2650 view_2->GetPreferredSize (&width, &height); 2664 view_2->GetPreferredSize (&width, &height);
2665 view_3->GetPreferredSize (&width_1, &height_1);
2651 2666
2652 return BSize (std::max (size_1.width, width), 2667 return BSize (std::max (size_1.width,
2653 std::max (size_1.height, height)); 2668 std::max (width_1, width)),
2669 std::max (size_1.height, height + height_1));
2654 } 2670 }
2655 2671
2656public: 2672public:
2657 DualLayoutView (BScrollView *first, BView *second) : BView (NULL, B_FRAME_EVENTS), 2673 TripleLayoutView (BScrollView *first, BView *second,
2658 view_1 (first), 2674 BView *third) : BView (NULL, B_FRAME_EVENTS),
2659 view_2 (second) 2675 view_1 (first),
2676 view_2 (second),
2677 view_3 (third)
2660 { 2678 {
2661 FrameResized (801, 801); 2679 FrameResized (801, 801);
2662 } 2680 }
@@ -2665,13 +2683,14 @@ public:
2665class EmacsFontSelectionDialog : public BWindow 2683class EmacsFontSelectionDialog : public BWindow
2666{ 2684{
2667 BView basic_view; 2685 BView basic_view;
2686 BCheckBox antialias_checkbox;
2668 BCheckBox preview_checkbox; 2687 BCheckBox preview_checkbox;
2669 BSplitView split_view; 2688 BSplitView split_view;
2670 BListView font_family_pane; 2689 BListView font_family_pane;
2671 BListView font_style_pane; 2690 BListView font_style_pane;
2672 BScrollView font_family_scroller; 2691 BScrollView font_family_scroller;
2673 BScrollView font_style_scroller; 2692 BScrollView font_style_scroller;
2674 DualLayoutView style_view; 2693 TripleLayoutView style_view;
2675 BObjectList<BStringItem> all_families; 2694 BObjectList<BStringItem> all_families;
2676 BObjectList<BStringItem> all_styles; 2695 BObjectList<BStringItem> all_styles;
2677 BButton cancel_button, ok_button; 2696 BButton cancel_button, ok_button;
@@ -2707,6 +2726,9 @@ class EmacsFontSelectionDialog : public BWindow
2707 message.AddInt32 ("emacs:family", family); 2726 message.AddInt32 ("emacs:family", family);
2708 message.AddInt32 ("emacs:style", style); 2727 message.AddInt32 ("emacs:style", style);
2709 2728
2729 if (antialias_checkbox.Value () == B_CONTROL_ON)
2730 message.AddBool ("emacs:disable_antialiasing", true);
2731
2710 message.AddString ("emacs:size", 2732 message.AddString ("emacs:size",
2711 size_entry.Text ()); 2733 size_entry.Text ());
2712 2734
@@ -2834,6 +2856,11 @@ class EmacsFontSelectionDialog : public BWindow
2834 rq.size = atoi (text); 2856 rq.size = atoi (text);
2835 rq.size_specified = rq.size > 0 || strlen (text); 2857 rq.size_specified = rq.size > 0 || strlen (text);
2836 2858
2859 if (antialias_checkbox.Value () == B_CONTROL_ON)
2860 rq.disable_antialias = true;
2861 else
2862 rq.disable_antialias = false;
2863
2837 write_port (comm_port, 0, &rq, sizeof rq); 2864 write_port (comm_port, 0, &rq, sizeof rq);
2838 } 2865 }
2839 else if (msg->what == B_CANCEL) 2866 else if (msg->what == B_CANCEL)
@@ -2859,6 +2886,11 @@ class EmacsFontSelectionDialog : public BWindow
2859 if (preview) 2886 if (preview)
2860 UpdatePreview (); 2887 UpdatePreview ();
2861 } 2888 }
2889 else if (msg->what == SET_DISABLE_ANTIALIASING)
2890 {
2891 if (preview)
2892 UpdatePreview ();
2893 }
2862 2894
2863 BWindow::MessageReceived (msg); 2895 BWindow::MessageReceived (msg);
2864 } 2896 }
@@ -2881,6 +2913,7 @@ public:
2881 2913
2882 font_family_pane.RemoveSelf (); 2914 font_family_pane.RemoveSelf ();
2883 font_style_pane.RemoveSelf (); 2915 font_style_pane.RemoveSelf ();
2916 antialias_checkbox.RemoveSelf ();
2884 preview_checkbox.RemoveSelf (); 2917 preview_checkbox.RemoveSelf ();
2885 style_view.RemoveSelf (); 2918 style_view.RemoveSelf ();
2886 font_family_scroller.RemoveSelf (); 2919 font_family_scroller.RemoveSelf ();
@@ -2897,12 +2930,15 @@ public:
2897 EmacsFontSelectionDialog (bool monospace_only, 2930 EmacsFontSelectionDialog (bool monospace_only,
2898 int initial_family_idx, 2931 int initial_family_idx,
2899 int initial_style_idx, 2932 int initial_style_idx,
2900 int initial_size) 2933 int initial_size,
2934 bool initial_antialias)
2901 : BWindow (BRect (0, 0, 500, 500), 2935 : BWindow (BRect (0, 0, 500, 500),
2902 "Select font from list", 2936 "Select font from list",
2903 B_TITLED_WINDOW_LOOK, 2937 B_TITLED_WINDOW_LOOK,
2904 B_MODAL_APP_WINDOW_FEEL, 0), 2938 B_MODAL_APP_WINDOW_FEEL, 0),
2905 basic_view (NULL, 0), 2939 basic_view (NULL, 0),
2940 antialias_checkbox ("Disable antialiasing", "Disable antialiasing",
2941 new BMessage (SET_DISABLE_ANTIALIASING)),
2906 preview_checkbox ("Show preview", "Show preview", 2942 preview_checkbox ("Show preview", "Show preview",
2907 new BMessage (SET_PREVIEW_DIALOG)), 2943 new BMessage (SET_PREVIEW_DIALOG)),
2908 font_family_pane (BRect (0, 0, 0, 0), NULL, 2944 font_family_pane (BRect (0, 0, 0, 0), NULL,
@@ -2917,7 +2953,8 @@ public:
2917 font_style_scroller (NULL, &font_style_pane, 2953 font_style_scroller (NULL, &font_style_pane,
2918 B_FOLLOW_ALL_SIDES, 2954 B_FOLLOW_ALL_SIDES,
2919 B_SUPPORTS_LAYOUT, false, true), 2955 B_SUPPORTS_LAYOUT, false, true),
2920 style_view (&font_style_scroller, &preview_checkbox), 2956 style_view (&font_style_scroller, &antialias_checkbox,
2957 &preview_checkbox),
2921 all_families (20, true), 2958 all_families (20, true),
2922 all_styles (20, true), 2959 all_styles (20, true),
2923 cancel_button ("Cancel", "Cancel", 2960 cancel_button ("Cancel", "Cancel",
@@ -2946,6 +2983,7 @@ public:
2946 split_view.AddChild (&font_family_scroller, 0.7); 2983 split_view.AddChild (&font_family_scroller, 0.7);
2947 split_view.AddChild (&style_view, 0.3); 2984 split_view.AddChild (&style_view, 0.3);
2948 style_view.AddChild (&font_style_scroller); 2985 style_view.AddChild (&font_style_scroller);
2986 style_view.AddChild (&antialias_checkbox);
2949 style_view.AddChild (&preview_checkbox); 2987 style_view.AddChild (&preview_checkbox);
2950 2988
2951 basic_view.SetViewUIColor (B_PANEL_BACKGROUND_COLOR); 2989 basic_view.SetViewUIColor (B_PANEL_BACKGROUND_COLOR);
@@ -3007,6 +3045,9 @@ public:
3007 sprintf (format_buffer, "%d", initial_size); 3045 sprintf (format_buffer, "%d", initial_size);
3008 size_entry.SetText (format_buffer); 3046 size_entry.SetText (format_buffer);
3009 } 3047 }
3048
3049 if (!initial_antialias)
3050 antialias_checkbox.SetValue (B_CONTROL_ON);
3010 } 3051 }
3011 3052
3012 void 3053 void
@@ -5096,7 +5137,8 @@ be_select_font (void (*process_pending_signals_function) (void),
5096 haiku_font_family_or_style *style, 5137 haiku_font_family_or_style *style,
5097 int *size, bool allow_monospace_only, 5138 int *size, bool allow_monospace_only,
5098 int initial_family, int initial_style, 5139 int initial_family, int initial_style,
5099 int initial_size) 5140 int initial_size, bool initial_antialias,
5141 bool *disable_antialias)
5100{ 5142{
5101 EmacsFontSelectionDialog *dialog; 5143 EmacsFontSelectionDialog *dialog;
5102 struct font_selection_dialog_message msg; 5144 struct font_selection_dialog_message msg;
@@ -5106,7 +5148,7 @@ be_select_font (void (*process_pending_signals_function) (void),
5106 5148
5107 dialog = new EmacsFontSelectionDialog (allow_monospace_only, 5149 dialog = new EmacsFontSelectionDialog (allow_monospace_only,
5108 initial_family, initial_style, 5150 initial_family, initial_style,
5109 initial_size); 5151 initial_size, initial_antialias);
5110 dialog->CenterOnScreen (); 5152 dialog->CenterOnScreen ();
5111 5153
5112 if (dialog->InitCheck () < B_OK) 5154 if (dialog->InitCheck () < B_OK)
@@ -5135,6 +5177,7 @@ be_select_font (void (*process_pending_signals_function) (void),
5135 memcpy (family, family_buffer, sizeof *family); 5177 memcpy (family, family_buffer, sizeof *family);
5136 memcpy (style, style_buffer, sizeof *style); 5178 memcpy (style, style_buffer, sizeof *style);
5137 *size = msg.size_specified ? msg.size : -1; 5179 *size = msg.size_specified ? msg.size : -1;
5180 *disable_antialias = msg.disable_antialias;
5138 5181
5139 return true; 5182 return true;
5140} 5183}
diff --git a/src/haiku_support.h b/src/haiku_support.h
index 97c2b6904af..3484fe0bbec 100644
--- a/src/haiku_support.h
+++ b/src/haiku_support.h
@@ -703,7 +703,8 @@ extern bool be_replay_menu_bar_event (void *, struct haiku_menu_bar_click_event
703extern bool be_select_font (void (*) (void), bool (*) (void), 703extern bool be_select_font (void (*) (void), bool (*) (void),
704 haiku_font_family_or_style *, 704 haiku_font_family_or_style *,
705 haiku_font_family_or_style *, 705 haiku_font_family_or_style *,
706 int *, bool, int, int, int); 706 int *, bool, int, int, int,
707 bool, bool *);
707 708
708extern int be_find_font_indices (struct haiku_font_pattern *, int *, int *); 709extern int be_find_font_indices (struct haiku_font_pattern *, int *, int *);
709extern status_t be_roster_launch (const char *, const char *, char **, 710extern status_t be_roster_launch (const char *, const char *, char **,
diff --git a/src/haikufont.c b/src/haikufont.c
index e9a25c0d58b..3e7f6f86dcb 100644
--- a/src/haikufont.c
+++ b/src/haikufont.c
@@ -492,6 +492,14 @@ haikufont_pattern_from_object (struct haiku_font_pattern *pattern,
492 pattern->specified |= FSPEC_WIDTH; 492 pattern->specified |= FSPEC_WIDTH;
493 pattern->width = haikufont_lisp_to_width (val); 493 pattern->width = haikufont_lisp_to_width (val);
494 } 494 }
495
496 val = assq_no_quit (QCantialias,
497 AREF (font_object, FONT_EXTRA_INDEX));
498 if (CONSP (val))
499 {
500 pattern->specified |= FSPEC_ANTIALIAS;
501 pattern->use_antialiasing = !NILP (XCDR (val));
502 }
495} 503}
496 504
497static void 505static void
@@ -1232,6 +1240,7 @@ in the font selection dialog. */)
1232 int rc, size, initial_family, initial_style, initial_size; 1240 int rc, size, initial_family, initial_style, initial_size;
1233 struct haiku_font_pattern pattern; 1241 struct haiku_font_pattern pattern;
1234 Lisp_Object lfamily, lweight, lslant, lwidth, ladstyle, lsize; 1242 Lisp_Object lfamily, lweight, lslant, lwidth, ladstyle, lsize;
1243 bool disable_antialiasing, initial_antialias;
1235 1244
1236 f = decode_window_system_frame (frame); 1245 f = decode_window_system_frame (frame);
1237 1246
@@ -1241,6 +1250,7 @@ in the font selection dialog. */)
1241 initial_style = -1; 1250 initial_style = -1;
1242 initial_family = -1; 1251 initial_family = -1;
1243 initial_size = -1; 1252 initial_size = -1;
1253 initial_antialias = true;
1244 1254
1245 font = FRAME_FONT (f); 1255 font = FRAME_FONT (f);
1246 1256
@@ -1254,6 +1264,11 @@ in the font selection dialog. */)
1254 haikufont_done_with_query_pattern (&pattern); 1264 haikufont_done_with_query_pattern (&pattern);
1255 1265
1256 initial_size = font->pixel_size; 1266 initial_size = font->pixel_size;
1267
1268 /* This field is safe to access even after
1269 haikufont_done_with_query_pattern. */
1270 if (pattern.specified & FSPEC_ANTIALIAS)
1271 initial_antialias = pattern.use_antialiasing;
1257 } 1272 }
1258 1273
1259 popup_activated_p++; 1274 popup_activated_p++;
@@ -1263,7 +1278,8 @@ in the font selection dialog. */)
1263 &family, &style, &size, 1278 &family, &style, &size,
1264 !NILP (exclude_proportional), 1279 !NILP (exclude_proportional),
1265 initial_family, initial_style, 1280 initial_family, initial_style,
1266 initial_size); 1281 initial_size, initial_antialias,
1282 &disable_antialiasing);
1267 request_sigio (); 1283 request_sigio ();
1268 popup_activated_p--; 1284 popup_activated_p--;
1269 1285
@@ -1280,9 +1296,15 @@ in the font selection dialog. */)
1280 lwidth = (pattern.specified & FSPEC_WIDTH 1296 lwidth = (pattern.specified & FSPEC_WIDTH
1281 ? haikufont_width_to_lisp (pattern.width) : Qnil); 1297 ? haikufont_width_to_lisp (pattern.width) : Qnil);
1282 ladstyle = (pattern.specified & FSPEC_STYLE 1298 ladstyle = (pattern.specified & FSPEC_STYLE
1283 ? intern (pattern.style) : Qnil); 1299 ? intern (pattern.style) : Qnil);
1284 lsize = (size >= 0 ? make_fixnum (size) : Qnil); 1300 lsize = (size >= 0 ? make_fixnum (size) : Qnil);
1285 1301
1302 if (disable_antialiasing)
1303 return CALLN (Ffont_spec, QCfamily, lfamily,
1304 QCweight, lweight, QCslant, lslant,
1305 QCwidth, lwidth, QCadstyle, ladstyle,
1306 QCsize, lsize, QCantialias, Qnil);
1307
1286 return CALLN (Ffont_spec, QCfamily, lfamily, 1308 return CALLN (Ffont_spec, QCfamily, lfamily,
1287 QCweight, lweight, QCslant, lslant, 1309 QCweight, lweight, QCslant, lslant,
1288 QCwidth, lwidth, QCadstyle, ladstyle, 1310 QCwidth, lwidth, QCadstyle, ladstyle,