* @returns {OSGUI$Window}
()
| 50 | * @returns {OSGUI$Window} |
| 51 | */ |
| 52 | function $FontBox() { |
| 53 | const $fb = $(E("div")).addClass("font-box"); |
| 54 | |
| 55 | // This complex cast tells it that jQuery's val() method can return a string and not an array of strings. |
| 56 | // See the types for val(). |
| 57 | const $family = /** @type {JQuery<HTMLSelectElement & { type: "select-one" }>} */( |
| 58 | $(E("select")).addClass("inset-deep").attr({ |
| 59 | "aria-label": "Font Family", |
| 60 | "aria-description": localize("Selects the font used by the text."), |
| 61 | }) |
| 62 | ); |
| 63 | const $size = $(E("input")).addClass("inset-deep").attr({ |
| 64 | type: "number", |
| 65 | min: 8, |
| 66 | max: 72, |
| 67 | value: text_tool_font.size, |
| 68 | "aria-label": "Font Size", |
| 69 | "aria-description": localize("Selects the point size of the text."), |
| 70 | }).css({ |
| 71 | maxWidth: 50, |
| 72 | }); |
| 73 | const $button_group = $(E("span")).addClass("text-toolbar-button-group"); |
| 74 | // @TODO: localized labels |
| 75 | const $bold = $Toggle(0, "bold", "Bold", localize("Sets or clears the text bold attribute.")); |
| 76 | const $italic = $Toggle(1, "italic", "Italic", localize("Sets or clears the text italic attribute.")); |
| 77 | const $underline = $Toggle(2, "underline", "Underline", localize("Sets or clears the text underline attribute.")); |
| 78 | // The original text from MS Paint is simply not true: browsers that support vertical writing also work with Latin text |
| 79 | // However, vertical-lr is a bit weird for Latin text. |
| 80 | // const $vertical = $Toggle(3, "vertical", "Vertical Writing Mode", localize("Only a Far East font can be used for vertical editing.")); |
| 81 | // So alternate text, which we won't have translations for... |
| 82 | const $vertical = $Toggle(3, "vertical", "Vertical Writing Mode", localize("Vertical writing is intended for Far East scripts.")); |
| 83 | // const $vertical = $Toggle(3, "vertical", "Vertical Writing Mode", localize("Vertical writing works best with Far East scripts.")); |
| 84 | $vertical.prop("disabled", !supports_vertical_writing_mode()); |
| 85 | |
| 86 | $button_group.append($bold, $italic, $underline, $vertical); |
| 87 | $fb.append($family, $size, $button_group); |
| 88 | |
| 89 | const update_font = () => { |
| 90 | text_tool_font.size = Number($size.val()); |
| 91 | text_tool_font.family = $family.val(); |
| 92 | $G.trigger("option-changed"); |
| 93 | }; |
| 94 | |
| 95 | const originalFamily = text_tool_font.family; |
| 96 | eachFont((font) => { |
| 97 | const $option = $(E("option")); |
| 98 | $option.val(font).text(font.name); |
| 99 | // Insert in alphabetical order |
| 100 | const $options = $family.children("option"); |
| 101 | let i = 0; |
| 102 | for (; i < $options.length; i++) { |
| 103 | if ($options.eq(i).text().localeCompare(font.name) > 0) { |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | if ($options.eq(i).length) { |
| 108 | $options.eq(i).before($option); |
| 109 | } else { |
no test coverage detected