Skip to content

Commit 3c2b2e9

Browse files
committed
Allow users to control the font used in diffs
1 parent 43dd12c commit 3c2b2e9

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

pinc/DifferenceEngineWrapperTable.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DifferenceEngineWrapperTable extends DifferenceEngineWrapper
5959
/**
6060
* Override default css for DP customizations
6161
*/
62-
function get_DifferenceEngine_css_data()
62+
function get_DifferenceEngine_css_data($font_family)
6363
{
6464
return "
6565
.diff-otitle,
@@ -70,7 +70,7 @@ function get_DifferenceEngine_css_data()
7070
.diff-addedline,
7171
.diff-deletedline,
7272
.diff-context {
73-
font-family: DP Sans Mono;
73+
font-family: $font_family, monospace;
7474
}
7575
/* Adjust padding to prevent descenders from being chopped off. Task 1936 */
7676
.diff-deletedline .diffchange,

tools/project_manager/diff.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
$only_nonempty_diffs = @$_GET['only_nonempty_diffs'] === 'on';
2727
$bb_diffs = (@$_GET['bb_diffs'] === 'on' and user_can_mentor_in_any_round());
2828

29+
$user_diff_font = Settings::get_Settings(User::current_username())->get_value("diff_font", "DP Sans Mono");
30+
$diff_fonts = array_diff(array_values(get_available_proofreading_font_faces()), ['']);
31+
$diff_font = get_enumerated_param($_GET, "diff_font", $user_diff_font, $diff_fonts);
32+
if ($diff_font != $user_diff_font) {
33+
Settings::get_Settings(User::current_username())->set_value("diff_font", $diff_font);
34+
}
2935

3036
$project = new Project($projectid);
3137
$state = $project->state;
@@ -92,7 +98,7 @@
9298
$image_url = "$code_url/tools/page_browser.php?project=$projectid&imagefile=$image";
9399
$image_link = sprintf($link_text, new_window_link($image_url, $image));
94100
$extra_args = [
95-
"css_data" => get_DifferenceEngine_css_data(),
101+
"css_data" => get_DifferenceEngine_css_data($diff_font),
96102
"js_data" => "
97103
function copyToClip(textstring) {
98104
navigator.clipboard.writeText(textstring).catch(function () {alert('Unable to copy!');});
@@ -113,7 +119,8 @@ function copyToClip(textstring) {
113119
$L_user,
114120
$format,
115121
$only_nonempty_diffs,
116-
$bb_diffs
122+
$bb_diffs,
123+
$diff_font
117124
);
118125
echo $navigation_text;
119126

@@ -183,8 +190,11 @@ function get_navigation(
183190
$L_user,
184191
$format,
185192
$only_nonempty_diffs,
186-
$bb_diffs
193+
$bb_diffs,
194+
$diff_font
187195
) {
196+
global $diff_fonts;
197+
188198
$navigation_text = "";
189199
$jump_to_js = "this.form.image.value=this.form.jumpto[this.form.jumpto.selectedIndex].value; this.form.submit();";
190200

@@ -273,6 +283,17 @@ function get_navigation(
273283

274284
$navigation_text .= "\n<input type='checkbox' name='only_nonempty_diffs' $checked_attribute id='only_nonempty_diffs' onclick='this.form.submit()'>\n";
275285
$navigation_text .= "\n<label for='only_nonempty_diffs'>" . html_safe(_('Skip empty diffs')) . "</label>\n";
286+
287+
$navigation_text .= "&nbsp;&middot;&nbsp;";
288+
289+
$navigation_text .= "\n<label for='diff_font'>" . html_safe(_('Font')) . ": </label>\n";
290+
$navigation_text .= "\n<select name='diff_font' id='diff_font' onchange='this.form.submit()'>\n";
291+
foreach ($diff_fonts as $font_family) {
292+
$selected = $font_family == $diff_font ? "selected" : "";
293+
$navigation_text .= "\n<option value='" . attr_safe($font_family) . "' $selected>" . html_safe($font_family) . "</option>";
294+
}
295+
$navigation_text .= "\n</select>";
296+
276297
$navigation_text .= "\n</form>\n";
277298

278299
return $navigation_text;

0 commit comments

Comments
 (0)