From fbe044a2b98f22e81af71db7b66a6a211cfc8c76 Mon Sep 17 00:00:00 2001 From: abakkk Date: Sat, 27 Jun 2020 15:10:01 +0200 Subject: [PATCH] Add text alignment Left or right. Replace unused `rtl`. --- data/default.css | 3 ++ draw.js | 41 +++++++++++++----- extension.js | 1 + locale/draw-on-your-screen.pot | 11 ++++- prefs.js | 3 +- schemas/gschemas.compiled | Bin 4192 -> 4280 bytes ...extensions.draw-on-your-screen.gschema.xml | 5 +++ 7 files changed, 51 insertions(+), 13 deletions(-) diff --git a/data/default.css b/data/default.css index 819219a..4a03e08 100644 --- a/data/default.css +++ b/data/default.css @@ -30,6 +30,8 @@ * Font family can be any font installed, or a generic family name (Serif, Sans-Serif, Monospace, Cursive, Fantasy). * Font weight and font style : no upper case when string. * + * text-align: left or right. + * */ .draw-on-your-screen { @@ -50,6 +52,7 @@ font-family: Cantarell; font-weight: normal; font-style: normal; + text-align: left; } /* Palette */ diff --git a/draw.js b/draw.js index d75088f..a926fd6 100644 --- a/draw.js +++ b/draw.js @@ -52,7 +52,6 @@ const CAIRO_DEBUG_EXTENDS = false; const SVG_DEBUG_EXTENDS = false; const SVG_DEBUG_SUPERPOSES_CAIRO = false; const TEXT_CURSOR_TIME = 600; // ms -const ENABLE_RTL = false; const ICON_DIR = Me.dir.get_child('data').get_child('icons'); const COLOR_ICON_PATH = ICON_DIR.get_child('color-symbolic.svg').get_path(); @@ -227,6 +226,7 @@ var DrawingArea = new Lang.Class({ this.newThemeAttributes.FontStyle = font.get_style(); this.newThemeAttributes.FontStretch = font.get_stretch(); this.newThemeAttributes.FontVariant = font.get_variant(); + this.newThemeAttributes.TextRightAligned = themeNode.get_text_align() == St.TextAlign.RIGHT; this.newThemeAttributes.LineWidth = themeNode.get_length('-drawing-line-width'); this.newThemeAttributes.LineJoin = themeNode.get_double('-drawing-line-join'); this.newThemeAttributes.LineCap = themeNode.get_double('-drawing-line-cap'); @@ -601,7 +601,7 @@ var DrawingArea = new Lang.Class({ stretch: this.currentFontStretch, variant: this.currentFontVariant }; this.currentElement.text = _("Text"); - this.currentElement.rtl = ENABLE_RTL && this.get_text_direction() == Clutter.TextDirection.RTL; + this.currentElement.textRightAligned = this.currentTextRightAligned; } this.currentElement.startDrawing(startX, startY); @@ -932,6 +932,15 @@ var DrawingArea = new Lang.Class({ this.emit('show-osd', null, `${_(currentFontFamily)}`, "", -1); }, + toggleTextAlignment: function() { + this.currentTextRightAligned = !this.currentTextRightAligned; + if (this.currentElement && this.currentElement.textRightAligned !== undefined) { + this.currentElement.textRightAligned = this.currentTextRightAligned; + this._redisplay(); + } + this.emit('show-osd', null, this.currentTextRightAligned ? _("Right aligned") : _("Left aligned"), "", -1); + }, + toggleHelp: function() { if (this.helper.visible) { this.helper.hideHelp(); @@ -1224,8 +1233,6 @@ const DrawingElement = new Lang.Class({ if (params.transformations === undefined) this.transformations = []; if (params.shape == Shapes.TEXT) { - if (params.rtl === undefined) - this.rtl = false; if (params.font && params.font.weight === 0) this.font.weight = 400; if (params.font && params.font.weight === 1) @@ -1258,7 +1265,7 @@ const DrawingElement = new Lang.Class({ transformations: this.transformations, text: this.text, lineIndex: this.lineIndex !== undefined ? this.lineIndex : undefined, - rtl: this.rtl, + textRightAligned: this.textRightAligned, font: this.font, points: this.points.map((point) => [Math.round(point[0]*100)/100, Math.round(point[1]*100)/100]) }; @@ -1384,7 +1391,7 @@ const DrawingElement = new Lang.Class({ layout.set_font_description(fontDescription); layout.set_text(this.text, -1); this.textWidth = layout.get_pixel_size()[0]; - cr.moveTo(points[1][0] - (this.rtl ? this.textWidth : 0), Math.max(points[0][1],points[1][1]) - layout.get_baseline() / Pango.SCALE); + cr.moveTo(points[1][0] - (this.textRightAligned ? this.textWidth : 0), Math.max(points[0][1],points[1][1]) - layout.get_baseline() / Pango.SCALE); layout.set_text(this.text, -1); PangoCairo.show_layout(cr, layout); @@ -1392,13 +1399,13 @@ const DrawingElement = new Lang.Class({ let cursorPosition = this.cursorPosition == -1 ? this.text.length : this.cursorPosition; layout.set_text(this.text.slice(0, cursorPosition), -1); let width = layout.get_pixel_size()[0]; - cr.rectangle(points[1][0] - (this.rtl ? this.textWidth : 0) + width, Math.max(points[0][1],points[1][1]), + cr.rectangle(points[1][0] - (this.textRightAligned ? this.textWidth : 0) + width, Math.max(points[0][1],points[1][1]), Math.abs(points[1][1] - points[0][1]) / 25, - Math.abs(points[1][1] - points[0][1])); cr.fill(); } if (params.showTextRectangle || params.drawTextRectangle) { - cr.rectangle(points[1][0] - (this.rtl ? this.textWidth : 0), Math.max(points[0][1], points[1][1]), + cr.rectangle(points[1][0] - (this.textRightAligned ? this.textWidth : 0), Math.max(points[0][1], points[1][1]), this.textWidth, - Math.abs(points[1][1] - points[0][1])); if (params.showTextRectangle) setDummyStroke(cr); @@ -1541,7 +1548,8 @@ const DrawingElement = new Lang.Class({ if (this.font.variant && FontVariantNames[this.font.variant]) attributes += ` font-variant="${FontVariantNames[this.font.variant].toLowerCase()}"`; - row += `${this.text}`; } @@ -1747,6 +1755,7 @@ const DrawingElement = new Lang.Class({ }, // The figure rotation center before transformations (original). + // this.textWidth is computed during Cairo building. _getOriginalCenter: function() { if (!this._originalCenter) { let points = this.points; @@ -2169,8 +2178,10 @@ const DrawingMenu = new Lang.Class({ this._addSubMenuItem(fontSection, 'font-x-generic-symbolic', FontGenericNamesCopy, this.area, 'currentFontGeneric'); this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', FontWeightNames, this.area, 'currentFontWeight'); this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', FontStyleNames, this.area, 'currentFontStyle'); + this._addSwitchItem(fontSection, _("Right aligned"), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned'); this._addSeparator(fontSection); this.menu.addMenuItem(fontSection); + fontSection.itemActivated = () => {}; this.fontSection = fontSection; let manager = Extension.manager; @@ -2215,11 +2226,19 @@ const DrawingMenu = new Lang.Class({ item.icon = new St.Icon({ style_class: 'popup-menu-icon' }); getActor(item).insert_child_at_index(item.icon, 1); - item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse); + let icon = target[targetProperty] ? iconTrue : iconFalse; + if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon)) + item.icon.set_gicon(icon); + else if (icon) + item.icon.set_icon_name(icon); item.connect('toggled', (item, state) => { target[targetProperty] = state; - item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse); + let icon = target[targetProperty] ? iconTrue : iconFalse; + if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon)) + item.icon.set_gicon(icon); + else if (icon) + item.icon.set_icon_name(icon); if (onToggled) onToggled(); }); diff --git a/extension.js b/extension.js index 26cefb5..96e3551 100644 --- a/extension.js +++ b/extension.js @@ -214,6 +214,7 @@ var AreaManager = new Lang.Class({ 'toggle-font-family': this.activeArea.toggleFontFamily.bind(this.activeArea), 'toggle-font-weight': this.activeArea.toggleFontWeight.bind(this.activeArea), 'toggle-font-style': this.activeArea.toggleFontStyle.bind(this.activeArea), + 'toggle-text-alignment': this.activeArea.toggleTextAlignment.bind(this.activeArea), 'toggle-panel-and-dock-visibility': this.togglePanelAndDockOpacity.bind(this), 'toggle-help': this.activeArea.toggleHelp.bind(this.activeArea), 'open-user-stylesheet': this.openUserStyleFile.bind(this), diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 18fa325..38b4edf 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -108,6 +108,12 @@ msgstr "" msgid "%d px" msgstr "" +msgid "Right aligned" +msgstr "" + +msgid "Left aligned" +msgstr "" + #: helper msgid "Screenshot" @@ -239,7 +245,7 @@ msgstr "" msgid "Change linecap" msgstr "" -msgid "Change fill rule" +msgid "Toggle fill rule" msgstr "" #: already in draw.js @@ -255,6 +261,9 @@ msgstr "" msgid "Change font style" msgstr "" +msgid "Toggle text alignment" +msgstr "" + msgid "Hide panel and dock" msgstr "" diff --git a/prefs.js b/prefs.js index 1f6cc25..3ea6e30 100644 --- a/prefs.js +++ b/prefs.js @@ -59,7 +59,7 @@ var INTERNAL_KEYBINDINGS = { 'select-mirror-tool': "Select mirror", '-separator-2': '', 'toggle-fill': "Toggle fill/stroke", - 'toggle-fill-rule': "Change fill rule", + 'toggle-fill-rule': "Toggle fill rule", '-separator-3': '', 'increment-line-width': "Increment line width", 'decrement-line-width': "Decrement line width", @@ -72,6 +72,7 @@ var INTERNAL_KEYBINDINGS = { 'toggle-font-family': "Change font family (generic name)", 'toggle-font-weight': "Change font weight", 'toggle-font-style': "Change font style", + 'toggle-text-alignment': "Toggle text alignment", '-separator-5': '', 'toggle-panel-and-dock-visibility': "Hide panel and dock", 'toggle-background': "Add a drawing background", diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index fda9879c7f963d5e881c849b17159b30b433f063..4ce499444b20d3b7b8ae1ad8e742897db4aa73c6 100644 GIT binary patch literal 4280 zcmai1ZHN_B7@jRHzxQgXt8S&Hc{iK8yXyLdZflvE73{JYOH?|0@7a5gJ9lQ9nY&+_ zNCkbEAW^hbk`<&z;6^4YhW4Y7An-?&5s`vH1<3}1LXteOw8RBtw%ct{t1}d+}}hy_3f}<2T#Nx!~9Y+ zzf-_hfIVAluh5@5@CUD*plRp*eV@`!Jp=8uf+di;!p`Hf&dGOD`1ATv7pg;9g*oVO>OvHoAPEGrKa0{?e*{Nx71v|jUU+=GB zJJjs=CGc^ew0_$$+Nr0*ejfY-@Q`YUn(h1wo`A{U^TNE8kF z173XZ-i!37o)7yV_$aVh`BT&XB={n5Xvc{z`cpHWVQ|%CP1~aUsp+2rHvkVSJ2mYs z;2pqLWv8ay0UrR&w(a+`eQL%(1pWp%cx<6fJN0DPFM@vuo<949Njo+3#>GD!c=Jr# z5be~Q-!ynVaOka9-lm;81$!%a5YXm+{}1idoZlnhGr+lL_e|z~rXCObdGOyr-EZ|1 z=ugc&q^4s30CS%x$4SjN8^9ZY&a`NxKQ-532ly%AwHuc|qn(=m1@K~{-z2XO4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kBe@C@gHg5(^2jWJTn)dFG$s_WV+HZOcyhxa@|Ic z?c1HUV+WOGndDU%ofikqnWf}@_xSt!lpWzCDmSSz^CF?H7*iqS{8dW8(YmW?t^uRl>oV zT13f?AH7|wLnqrEzf|LRsQYHi8du}TVXGKH+UJqZvyt+SztB5 zz8tL@4p;V7>M7Iv|5sbEsn3}OfR3xxvZxw;Hn+F|AGnf zMPcK32(&V}S{dalJ=2$|H(GjqOUyJgPOlWs6MyNrtCFi#QQUBQl|0!cJ?ZA8AN%K2 zv1sc3pAO6qu`zL*leo=MT>Te(y4ocq9v!cVr<|Y;Sd{VjsKe^yYIPJ>&s(RN>&|-$ zM{FgX#ItjPxcD$m$6b?Lt%>5MA93xN=Ubcjubs%hWsHAI;@=YaM|JM8RoSl`Wnt!V SUg3GRP4&81`kYMtT>k;n5a!DO diff --git a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml index 38c9300..e9cb2bf 100644 --- a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml +++ b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml @@ -231,6 +231,11 @@ toggle font style toggle font style + + ["<Primary><Shift>a"] + toggle text alignment + toggle text alignment + ["<Primary>o"] open user stylesheet to edit style