Merge pull request #123 from Dpeta/alternian

Add alternian font tags (<alt></alt>)
This commit is contained in:
Dpeta 2023-02-25 02:18:12 +01:00 committed by GitHub
commit 829d981424
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 21 deletions

View file

@ -1,4 +1,8 @@
import re
import random
import itertools
import logging
from datetime import datetime
PchumLog = logging.getLogger("pchumLogger")
try:
@ -6,9 +10,6 @@ try:
except ImportError:
print("PyQt5 fallback (dataobjs.py)")
from PyQt5 import QtGui
from datetime import datetime
import re
import random
from mood import Mood
from parsetools import (
@ -31,6 +32,7 @@ _ctagre = re.compile("(</?c=?.*?>)", re.I)
_smilere = re.compile("|".join(list(smiledict.keys())))
_memore = re.compile(r"(\s|^)(#[A-Za-z0-9_]+)")
_handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)")
_alternian = re.compile(r"<alt>.*?</alt>")
class pesterQuirk:
@ -167,20 +169,18 @@ class pesterQuirks:
if checkstate == 2:
# Check for substring that should be excluded.
excludes = []
# Check for links, store in list.
for match in re.finditer(_urlre, string):
excludes.append(match)
# Check for smilies, store in list.
for match in re.finditer(_smilere, string):
excludes.append(match)
# Check for @handles, store in list.
for match in re.finditer(_handlere, string):
excludes.append(match)
# Check for #memos, store in list.
for match in re.finditer(_memore, string):
excludes.append(match)
# Return matches for links, smilies, handles, memos.
# Chain the iterators and add to excludes list.
matches = itertools.chain(
re.finditer(_urlre, string),
re.finditer(_smilere, string),
re.finditer(_handlere, string),
re.finditer(_memore, string),
re.finditer(_alternian, string),
)
excludes.extend(matches)
if len(excludes) >= 1:
if excludes:
# SORT !!!
excludes.sort(key=lambda exclude: exclude.start())
# Recursion check.

Binary file not shown.

2
fonts/alternian/info.txt Normal file
View file

@ -0,0 +1,2 @@
license: Public Domain
link: https://www.fontspace.com/allis-daedric-font-f20263

View file

@ -40,6 +40,8 @@ _oocre = re.compile(r"([\[(\{])\1.*([\])\}])\2")
# _format_end = re.compile(r"(?i)</([ibu])>")
_honk = re.compile(r"(?i)\bhonk\b")
_groupre = re.compile(r"\\([0-9]+)")
_alternian_begin = re.compile(r"<alt>") # Matches get set to alternian font
_alternian_end = re.compile(r"</alt>")
quirkloader = ScriptQuirks()
_functionre = None
@ -169,9 +171,9 @@ class hyperlink(lexercon.Chunk):
def convert(self, format):
if format == "html":
return "<a href='{}'>{}</a>".format(self.string, self.string)
return f"<a href='{self.string}'>{self.string}</a>"
elif format == "bbcode":
return "[url]%s[/url]" % (self.string)
return f"[url]{self.string}[/url]"
else:
return self.string
@ -184,6 +186,30 @@ class hyperlink_lazy(hyperlink):
self.string = "http://" + string
class alternianTagBegin(lexercon.Chunk):
def __init__(self, string):
self.string = string
def convert(self, format):
if format == "html":
return "<em style=\"font-family:'AllisDaedric'\">"
elif format == "text":
return ""
return self.string
class alternianTagEnd(lexercon.Chunk):
def __init__(self, string):
self.string = string
def convert(self, format):
if format == "html":
return "</em>"
elif format == "text":
return ""
return self.string
class imagelink(lexercon.Chunk):
def __init__(self, string, img):
self.string = string
@ -285,6 +311,8 @@ def kxlexMsg(msg: str):
def lexMessage(string: str):
lexlist = [
(mecmd, _mecmdre),
(alternianTagBegin, _alternian_begin),
(alternianTagEnd, _alternian_end),
(colorBegin, _ctag_begin),
# (colorBegin, _gtag_begin),
(colorEnd, _ctag_end),

View file

@ -1653,9 +1653,10 @@ class PesterWindow(MovingWindow):
if not self.config.defaultprofile():
self.changeProfile()
# Fuck you some more OSX leopard! >:(
# if not ostools.isOSXLeopard():
# QtCore.QTimer.singleShot(1000, self.mspacheck)
# Load font
QtGui.QFontDatabase.addApplicationFont(
os.path.join("fonts", "alternian", "AllisDaedric-VYWz.otf")
)
self.pcUpdate[str, str].connect(self.updateMsg)

View file

@ -17,6 +17,7 @@ add_data = [
"smilies;smilies",
"themes;themes",
"docs;docs",
"fonts;fonts",
"README.md;.",
"LICENSE;.",
"CHANGELOG.md;.",
@ -28,6 +29,7 @@ data_folders = {
"smilies": "smilies",
"themes": "themes",
"docs": "docs",
"fonts": "fonts",
}
data_files = {
"README.md": "README.md.txt",

View file

@ -56,6 +56,8 @@ def rainbow(text):
re.finditer(_smilere, text),
re.finditer(_memore, text),
re.finditer(_handlere, text),
re.finditer(_alternian_begin, text),
re.finditer(_alternian_end, text),
)
for match in match_chain:
for color_and_position in colors_and_positions:
@ -161,3 +163,5 @@ _smilere = re.compile("|".join(list(smiledict.keys())))
_urlre = re.compile(r"(?i)(?:^|(?<=\s))(?:(?:https?|ftp)://|magnet:)[^\s]+")
_memore = re.compile(r"(\s|^)(#[A-Za-z0-9_]+)")
_handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)")
_alternian_begin = re.compile(r"<alt>") # Matches get set to alternian font
_alternian_end = re.compile(r"</alt>")