Use DejaVuSans font instead of Noto (for text). Prevent triple-select selecting the checkbox/bullet
This commit is contained in:
parent
a3c74a218f
commit
f3ddd2a83c
5 changed files with 258 additions and 5 deletions
187
bouquin/fonts/DejaVu.license
Normal file
187
bouquin/fonts/DejaVu.license
Normal file
|
|
@ -0,0 +1,187 @@
|
||||||
|
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
|
||||||
|
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
|
||||||
|
|
||||||
|
|
||||||
|
Bitstream Vera Fonts Copyright
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
|
||||||
|
a trademark of Bitstream, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of the fonts accompanying this license ("Fonts") and associated
|
||||||
|
documentation files (the "Font Software"), to reproduce and distribute the
|
||||||
|
Font Software, including without limitation the rights to use, copy, merge,
|
||||||
|
publish, distribute, and/or sell copies of the Font Software, and to permit
|
||||||
|
persons to whom the Font Software is furnished to do so, subject to the
|
||||||
|
following conditions:
|
||||||
|
|
||||||
|
The above copyright and trademark notices and this permission notice shall
|
||||||
|
be included in all copies of one or more of the Font Software typefaces.
|
||||||
|
|
||||||
|
The Font Software may be modified, altered, or added to, and in particular
|
||||||
|
the designs of glyphs or characters in the Fonts may be modified and
|
||||||
|
additional glyphs or characters may be added to the Fonts, only if the fonts
|
||||||
|
are renamed to names not containing either the words "Bitstream" or the word
|
||||||
|
"Vera".
|
||||||
|
|
||||||
|
This License becomes null and void to the extent applicable to Fonts or Font
|
||||||
|
Software that has been modified and is distributed under the "Bitstream
|
||||||
|
Vera" names.
|
||||||
|
|
||||||
|
The Font Software may be sold as part of a larger software package but no
|
||||||
|
copy of one or more of the Font Software typefaces may be sold by itself.
|
||||||
|
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
||||||
|
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
||||||
|
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
|
||||||
|
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||||
|
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
|
||||||
|
FONT SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the names of Gnome, the Gnome
|
||||||
|
Foundation, and Bitstream Inc., shall not be used in advertising or
|
||||||
|
otherwise to promote the sale, use or other dealings in this Font Software
|
||||||
|
without prior written authorization from the Gnome Foundation or Bitstream
|
||||||
|
Inc., respectively. For further information, contact: fonts at gnome dot
|
||||||
|
org.
|
||||||
|
|
||||||
|
Arev Fonts Copyright
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the fonts accompanying this license ("Fonts") and
|
||||||
|
associated documentation files (the "Font Software"), to reproduce
|
||||||
|
and distribute the modifications to the Bitstream Vera Font Software,
|
||||||
|
including without limitation the rights to use, copy, merge, publish,
|
||||||
|
distribute, and/or sell copies of the Font Software, and to permit
|
||||||
|
persons to whom the Font Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright and trademark notices and this permission notice
|
||||||
|
shall be included in all copies of one or more of the Font Software
|
||||||
|
typefaces.
|
||||||
|
|
||||||
|
The Font Software may be modified, altered, or added to, and in
|
||||||
|
particular the designs of glyphs or characters in the Fonts may be
|
||||||
|
modified and additional glyphs or characters may be added to the
|
||||||
|
Fonts, only if the fonts are renamed to names not containing either
|
||||||
|
the words "Tavmjong Bah" or the word "Arev".
|
||||||
|
|
||||||
|
This License becomes null and void to the extent applicable to Fonts
|
||||||
|
or Font Software that has been modified and is distributed under the
|
||||||
|
"Tavmjong Bah Arev" names.
|
||||||
|
|
||||||
|
The Font Software may be sold as part of a larger software package but
|
||||||
|
no copy of one or more of the Font Software typefaces may be sold by
|
||||||
|
itself.
|
||||||
|
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
|
||||||
|
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of Tavmjong Bah shall not
|
||||||
|
be used in advertising or otherwise to promote the sale, use or other
|
||||||
|
dealings in this Font Software without prior written authorization
|
||||||
|
from Tavmjong Bah. For further information, contact: tavmjong @ free
|
||||||
|
. fr.
|
||||||
|
|
||||||
|
TeX Gyre DJV Math
|
||||||
|
-----------------
|
||||||
|
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
|
||||||
|
|
||||||
|
Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
|
||||||
|
(on behalf of TeX users groups) are in public domain.
|
||||||
|
|
||||||
|
Letters imported from Euler Fraktur from AMSfonts are (c) American
|
||||||
|
Mathematical Society (see below).
|
||||||
|
Bitstream Vera Fonts Copyright
|
||||||
|
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
|
||||||
|
is a trademark of Bitstream, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of the fonts accompanying this license (“Fonts”) and associated
|
||||||
|
documentation
|
||||||
|
files (the “Font Software”), to reproduce and distribute the Font Software,
|
||||||
|
including without limitation the rights to use, copy, merge, publish,
|
||||||
|
distribute,
|
||||||
|
and/or sell copies of the Font Software, and to permit persons to whom
|
||||||
|
the Font Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright and trademark notices and this permission notice
|
||||||
|
shall be
|
||||||
|
included in all copies of one or more of the Font Software typefaces.
|
||||||
|
|
||||||
|
The Font Software may be modified, altered, or added to, and in particular
|
||||||
|
the designs of glyphs or characters in the Fonts may be modified and
|
||||||
|
additional
|
||||||
|
glyphs or characters may be added to the Fonts, only if the fonts are
|
||||||
|
renamed
|
||||||
|
to names not containing either the words “Bitstream” or the word “Vera”.
|
||||||
|
|
||||||
|
This License becomes null and void to the extent applicable to Fonts or
|
||||||
|
Font Software
|
||||||
|
that has been modified and is distributed under the “Bitstream Vera”
|
||||||
|
names.
|
||||||
|
|
||||||
|
The Font Software may be sold as part of a larger software package but
|
||||||
|
no copy
|
||||||
|
of one or more of the Font Software typefaces may be sold by itself.
|
||||||
|
|
||||||
|
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
||||||
|
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
||||||
|
FOUNDATION
|
||||||
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
|
||||||
|
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
|
||||||
|
ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
|
||||||
|
INABILITY TO USE
|
||||||
|
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
|
Except as contained in this notice, the names of GNOME, the GNOME
|
||||||
|
Foundation,
|
||||||
|
and Bitstream Inc., shall not be used in advertising or otherwise to promote
|
||||||
|
the sale, use or other dealings in this Font Software without prior written
|
||||||
|
authorization from the GNOME Foundation or Bitstream Inc., respectively.
|
||||||
|
For further information, contact: fonts at gnome dot org.
|
||||||
|
|
||||||
|
AMSFonts (v. 2.2) copyright
|
||||||
|
|
||||||
|
The PostScript Type 1 implementation of the AMSFonts produced by and
|
||||||
|
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
|
||||||
|
available for general use. This has been accomplished through the
|
||||||
|
cooperation
|
||||||
|
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
|
||||||
|
Members of this consortium include:
|
||||||
|
|
||||||
|
Elsevier Science IBM Corporation Society for Industrial and Applied
|
||||||
|
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
|
||||||
|
|
||||||
|
In order to assure the authenticity of these fonts, copyright will be
|
||||||
|
held by
|
||||||
|
the American Mathematical Society. This is not meant to restrict in any way
|
||||||
|
the legitimate use of the fonts, such as (but not limited to) electronic
|
||||||
|
distribution of documents containing these fonts, inclusion of these fonts
|
||||||
|
into other public domain or commercial font collections or computer
|
||||||
|
applications, use of the outline data to create derivative fonts and/or
|
||||||
|
faces, etc. However, the AMS does require that the AMS copyright notice be
|
||||||
|
removed from any derivative versions of the fonts which have been altered in
|
||||||
|
any way. In addition, to ensure the fidelity of TeX documents using Computer
|
||||||
|
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
|
||||||
|
has requested that any alterations which yield different font metrics be
|
||||||
|
given a different name.
|
||||||
|
|
||||||
|
$Id$
|
||||||
BIN
bouquin/fonts/DejaVuSans.ttf
Normal file
BIN
bouquin/fonts/DejaVuSans.ttf
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -46,18 +46,14 @@ class MarkdownEditor(QTextEdit):
|
||||||
base_dir = Path(__file__).resolve().parent
|
base_dir = Path(__file__).resolve().parent
|
||||||
|
|
||||||
# Load regular text font (primary)
|
# Load regular text font (primary)
|
||||||
regular_font_path = base_dir / "fonts" / "NotoSans-Regular.ttf"
|
regular_font_path = base_dir / "fonts" / "DejaVuSans.ttf"
|
||||||
regular_font_id = QFontDatabase.addApplicationFont(str(regular_font_path))
|
regular_font_id = QFontDatabase.addApplicationFont(str(regular_font_path))
|
||||||
if regular_font_id == -1:
|
|
||||||
print("Failed to load NotoSans-Regular.ttf")
|
|
||||||
|
|
||||||
# Load Symbols font (fallback)
|
# Load Symbols font (fallback)
|
||||||
symbols_font_path = base_dir / "fonts" / "NotoSansSymbols2-Regular.ttf"
|
symbols_font_path = base_dir / "fonts" / "NotoSansSymbols2-Regular.ttf"
|
||||||
symbols_font_id = QFontDatabase.addApplicationFont(str(symbols_font_path))
|
symbols_font_id = QFontDatabase.addApplicationFont(str(symbols_font_path))
|
||||||
symbols_families = QFontDatabase.applicationFontFamilies(symbols_font_id)
|
symbols_families = QFontDatabase.applicationFontFamilies(symbols_font_id)
|
||||||
self.symbols_font_family = symbols_families[0]
|
self.symbols_font_family = symbols_families[0]
|
||||||
if symbols_font_id == -1:
|
|
||||||
print("Failed to load NotoSansSymbols2-Regular.ttf")
|
|
||||||
|
|
||||||
# Use the regular Noto Sans family as the editor font
|
# Use the regular Noto Sans family as the editor font
|
||||||
regular_families = QFontDatabase.applicationFontFamilies(regular_font_id)
|
regular_families = QFontDatabase.applicationFontFamilies(regular_font_id)
|
||||||
|
|
@ -92,6 +88,13 @@ class MarkdownEditor(QTextEdit):
|
||||||
# Track if we're currently updating text programmatically
|
# Track if we're currently updating text programmatically
|
||||||
self._updating = False
|
self._updating = False
|
||||||
|
|
||||||
|
# Guard to avoid recursive selection tweaks
|
||||||
|
self._adjusting_selection = False
|
||||||
|
|
||||||
|
# After selections change, trim list prefixes from full-line selections
|
||||||
|
# (e.g. after triple-clicking a list item to select the line).
|
||||||
|
self.selectionChanged.connect(self._maybe_trim_list_prefix_from_line_selection)
|
||||||
|
|
||||||
# Connect to text changes for smart formatting
|
# Connect to text changes for smart formatting
|
||||||
self.textChanged.connect(self._on_text_changed)
|
self.textChanged.connect(self._on_text_changed)
|
||||||
self.textChanged.connect(self._update_code_block_row_backgrounds)
|
self.textChanged.connect(self._update_code_block_row_backgrounds)
|
||||||
|
|
@ -486,6 +489,69 @@ class MarkdownEditor(QTextEdit):
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def _maybe_trim_list_prefix_from_line_selection(self) -> None:
|
||||||
|
"""
|
||||||
|
If the current selection looks like a full-line selection on a list item
|
||||||
|
(for example, from a triple-click), trim the selection so that it starts
|
||||||
|
just *after* the visual list prefix (checkbox / bullet / number), and
|
||||||
|
ends at the end of the text on that line (not on the next line's newline).
|
||||||
|
"""
|
||||||
|
# Avoid re-entry when we move the cursor ourselves.
|
||||||
|
if getattr(self, "_adjusting_selection", False):
|
||||||
|
return
|
||||||
|
|
||||||
|
cursor = self.textCursor()
|
||||||
|
if not cursor.hasSelection():
|
||||||
|
return
|
||||||
|
|
||||||
|
start = cursor.selectionStart()
|
||||||
|
end = cursor.selectionEnd()
|
||||||
|
if start == end:
|
||||||
|
return
|
||||||
|
|
||||||
|
doc = self.document()
|
||||||
|
# 'end' is exclusive; use end - 1 so we land in the last selected block.
|
||||||
|
start_block = doc.findBlock(start)
|
||||||
|
end_block = doc.findBlock(end - 1)
|
||||||
|
if not start_block.isValid() or start_block != end_block:
|
||||||
|
# Only adjust single-line selections.
|
||||||
|
return
|
||||||
|
|
||||||
|
# How much list prefix (indent + checkbox/bullet/number) this block has
|
||||||
|
prefix_len = self._list_prefix_length_for_block(start_block)
|
||||||
|
if prefix_len <= 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
block_start = start_block.position()
|
||||||
|
prefix_end = block_start + prefix_len
|
||||||
|
|
||||||
|
# If the selection already starts after the prefix, nothing to do.
|
||||||
|
if start >= prefix_end:
|
||||||
|
return
|
||||||
|
|
||||||
|
line_text = start_block.text()
|
||||||
|
line_end = block_start + len(line_text) # end of visible text on this line
|
||||||
|
|
||||||
|
# Only treat it as a "full line" selection if it reaches the end of the
|
||||||
|
# visible text. Triple-click usually selects to at least here (often +1 for
|
||||||
|
# the newline).
|
||||||
|
if end < line_end:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Clamp the selection so that it ends at the end of this line's text,
|
||||||
|
# *not* at the newline / start of the next block. This keeps the caret
|
||||||
|
# blinking on the selected line instead of the next line.
|
||||||
|
visual_end = line_end
|
||||||
|
|
||||||
|
self._adjusting_selection = True
|
||||||
|
try:
|
||||||
|
new_cursor = self.textCursor()
|
||||||
|
new_cursor.setPosition(prefix_end)
|
||||||
|
new_cursor.setPosition(visual_end, QTextCursor.KeepAnchor)
|
||||||
|
self.setTextCursor(new_cursor)
|
||||||
|
finally:
|
||||||
|
self._adjusting_selection = False
|
||||||
|
|
||||||
def _detect_list_type(self, line: str) -> tuple[str | None, str]:
|
def _detect_list_type(self, line: str) -> tuple[str | None, str]:
|
||||||
"""
|
"""
|
||||||
Detect if line is a list item. Returns (list_type, prefix).
|
Detect if line is a list item. Returns (list_type, prefix).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue