Skip to content

Commit

Permalink
Add support for fractional font sizes
Browse files Browse the repository at this point in the history
Closes #2250 and #703.
  • Loading branch information
phao authored and b4n committed Aug 13, 2019
1 parent 21b06d1 commit 2453463
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/editor.c
Expand Up @@ -4591,19 +4591,20 @@ void editor_ensure_final_newline(GeanyEditor *editor)

void editor_set_font(GeanyEditor *editor, const gchar *font)
{
gint style, size;
gint style;
gchar *font_name;
PangoFontDescription *pfd;
gdouble size;

g_return_if_fail(editor);

pfd = pango_font_description_from_string(font);
size = pango_font_description_get_size(pfd) / PANGO_SCALE;
size = pango_font_description_get_size(pfd) / (gdouble) PANGO_SCALE;
font_name = g_strdup_printf("!%s", pango_font_description_get_family(pfd));
pango_font_description_free(pfd);

for (style = 0; style <= STYLE_MAX; style++)
sci_set_font(editor->sci, style, font_name, size);
sci_set_font_fractional(editor->sci, style, font_name, size);

g_free(font_name);

Expand Down
15 changes: 13 additions & 2 deletions src/sciwrappers.c
Expand Up @@ -939,6 +939,18 @@ gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
return (gint) SSM(sci, SCI_FINDTEXT, (uptr_t) flags, (sptr_t) ttf);
}

/* * Sets the font for a particular style.
* @param sci Scintilla widget.
* @param style The style.
* @param font The font name.
* @param size The font (fractional) size. */
void sci_set_font_fractional(ScintillaObject *sci, gint style, const gchar *font, gdouble size)
{
SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);

/* Adding 0.5 is for rounding. */
SSM(sci, SCI_STYLESETSIZEFRACTIONAL, (uptr_t) style, (sptr_t) (SC_FONT_SIZE_MULTIPLIER * size + 0.5));
}

/** Sets the font for a particular style.
* @param sci Scintilla widget.
Expand All @@ -948,8 +960,7 @@ gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
GEANY_API_SYMBOL
void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
{
SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);
SSM(sci, SCI_STYLESETSIZE, (uptr_t) style, size);
sci_set_font_fractional(sci, style, font, size);
}


Expand Down
2 changes: 2 additions & 0 deletions src/sciwrappers.h
Expand Up @@ -216,6 +216,8 @@ gint sci_text_width (ScintillaObject *sci, gint styleNumber, const gchar *
void sci_move_selected_lines_down (ScintillaObject *sci);
void sci_move_selected_lines_up (ScintillaObject *sci);

void sci_set_font_fractional (ScintillaObject *sci, gint style, const gchar *font, gdouble size);

#endif /* GEANY_PRIVATE */

G_END_DECLS
Expand Down

0 comments on commit 2453463

Please sign in to comment.