|
1 | 1 | # A part of NonVisual Desktop Access (NVDA) |
2 | 2 | # This file is covered by the GNU General Public License. |
3 | 3 | # See the file COPYING for more details. |
4 | | -# Copyright (C) 2021-2022 NV Access Limited, Cyrille Bougot |
| 4 | +# Copyright (C) 2021-2023 NV Access Limited, Cyrille Bougot |
5 | 5 |
|
6 | 6 | import re |
7 | 7 | from typing import Dict |
@@ -99,3 +99,83 @@ def translateFromAttribute(fontSize: str) -> str: |
99 | 99 | return FontSize._unitToTranslatableString[measurementUnit] % measurement |
100 | 100 | log.debugWarning(f"Unknown font-size value, can't translate '{fontSize}'") |
101 | 101 | return fontSize |
| 102 | + |
| 103 | + |
| 104 | +class TextAlign(DisplayStringStrEnum): |
| 105 | + """Values to use for 'text-align' NVDA format field. |
| 106 | + These describe the horizontal paragraph position. |
| 107 | + """ |
| 108 | + UNDEFINED = 'undefined' |
| 109 | + LEFT = 'left' |
| 110 | + CENTER = 'center' |
| 111 | + RIGHT = 'right' |
| 112 | + JUSTIFY = 'justify' |
| 113 | + DISTRIBUTE = 'distribute' |
| 114 | + CENTER_ACROSS_SELECTION = 'center-across-selection' |
| 115 | + GENERAL = 'general' |
| 116 | + FILL = 'fill' |
| 117 | + |
| 118 | + @property |
| 119 | + def _displayStringLabels(self): |
| 120 | + return _textAlignLabels |
| 121 | + |
| 122 | + |
| 123 | +#: Text to use for 'text-align format field values. These describe the horizontal position of a paragraph |
| 124 | +#: or a cell's content. |
| 125 | +_textAlignLabels: Dict[TextAlign, str] = { |
| 126 | + TextAlign.UNDEFINED: "", # There is nothing to report if no alignment is defined. |
| 127 | + # Translators: Reported when text is left-aligned. |
| 128 | + TextAlign.LEFT: _("align left"), |
| 129 | + # Translators: Reported when text is centered. |
| 130 | + TextAlign.CENTER: _("align center"), |
| 131 | + # Translators: Reported when text is right-aligned. |
| 132 | + TextAlign.RIGHT: _("align right"), |
| 133 | + # Translators: Reported when text is justified. |
| 134 | + # See http://en.wikipedia.org/wiki/Typographic_alignment#Justified |
| 135 | + TextAlign.JUSTIFY: _("align justify"), |
| 136 | + # Translators: Reported when text is justified with character spacing (Japanese etc) |
| 137 | + # See http://kohei.us/2010/01/21/distributed-text-justification/ |
| 138 | + TextAlign.DISTRIBUTE: _("align distributed"), |
| 139 | + # Translators: Reported when text is centered across multiple cells. |
| 140 | + TextAlign.CENTER_ACROSS_SELECTION: _("align center across multiple cells"), |
| 141 | + # Translators: Reported in Excel when text is formatted with "General" alignment, i.e. the name of the |
| 142 | + # alignment in Excel aligning the cell's content depending on its type: text left and numbers right. |
| 143 | + TextAlign.GENERAL: _("align general"), |
| 144 | + # Translators: Reported in Excel when text is formatted with "Fill" alignment, i.e. the name of the |
| 145 | + # alignment in Excel repeating the cell's content for the width of the cell. |
| 146 | + TextAlign.FILL: _("align fill"), |
| 147 | +} |
| 148 | + |
| 149 | + |
| 150 | +class VerticalTextAlign(DisplayStringStrEnum): |
| 151 | + """Values to use for 'vertical-align' NVDA format field. |
| 152 | + These describe the vertical text position, e.g. in a table cell. |
| 153 | + """ |
| 154 | + UNDEFINED = 'undefined' |
| 155 | + TOP = 'top' |
| 156 | + CENTER = 'center' |
| 157 | + BOTTOM = 'bottom' |
| 158 | + JUSTIFY = 'justify' |
| 159 | + DISTRIBUTE = 'distributed' |
| 160 | + |
| 161 | + @property |
| 162 | + def _displayStringLabels(self): |
| 163 | + return _verticalTextAlignLabels |
| 164 | + |
| 165 | + |
| 166 | +#: Text to use for 'vertical-align' format field values. These describe the vertical position |
| 167 | +#: of a cell's content. |
| 168 | +_verticalTextAlignLabels: Dict[VerticalTextAlign, str] = { |
| 169 | + VerticalTextAlign.UNDEFINED: "", # There is nothing to report if no vertical alignment is defined. |
| 170 | + # Translators: Reported when text is vertically top-aligned. |
| 171 | + VerticalTextAlign.TOP: _("vertical align top"), |
| 172 | + # Translators: Reported when text is vertically middle aligned. |
| 173 | + VerticalTextAlign.CENTER: _("vertical align middle"), |
| 174 | + # Translators: Reported when text is vertically bottom-aligned. |
| 175 | + VerticalTextAlign.BOTTOM: _("vertical align bottom"), |
| 176 | + # Translators: Reported when text is vertically justified. |
| 177 | + VerticalTextAlign.JUSTIFY: _("vertical align justified"), |
| 178 | + # Translators: Reported when text is vertically justified but with character spacing |
| 179 | + # (For some Asian content). |
| 180 | + VerticalTextAlign.DISTRIBUTE: _("vertical align distributed"), |
| 181 | +} |
0 commit comments