modify some function
This commit is contained in:
parent
fe20b8e21f
commit
932f596f08
7 changed files with 147 additions and 75 deletions
|
@ -1,6 +1,7 @@
|
|||
[def-syntax q [[_] [str "\""]]]
|
||||
[script "packages/font-fallback"]
|
||||
[script "packages/grid"]
|
||||
[script "packages/image"]
|
||||
|
||||
[define section-var 1]
|
||||
[define sub-section-var 1]
|
||||
|
@ -8,7 +9,7 @@
|
|||
|
||||
% custom macro
|
||||
[def-syntax section
|
||||
[[_ x][begin
|
||||
[[_ x][str-append-many
|
||||
[set! section-title [str-append [str-append [str section-var] [str ". " ]] [str x]]]
|
||||
[font [[size "20pt"][weight "800"]] section-title]
|
||||
[set! section-var [+ section-var 1]]
|
||||
|
@ -19,7 +20,7 @@
|
|||
|
||||
|
||||
[def-syntax subsection
|
||||
[[_ x][begin
|
||||
[[_ x][str-append-many
|
||||
[set! section-title [str-append [str-append [str sub-section-var] [str ". " ]] [str x]]]
|
||||
[font [[size "16pt"][weight "600"]] section-title]
|
||||
[set! sub-section-var [+ sub-section-var 1]]
|
||||
|
@ -55,15 +56,40 @@ The functions that it has (although may be buggy or needed to be tested) is:
|
|||
|
||||
[section "Simple manual"]
|
||||
|
||||
[subsection "Editor interface"]
|
||||
|
||||
[call img [[src "total-interface.png"] [height "200px"]]]
|
||||
|
||||
|
||||
|
||||
[subsection "Arimetic calculation and variable and function definition"]
|
||||
|
||||
[subsection "Special character"]
|
||||
|
||||
|
||||
[subsection "Font formatting"]
|
||||
|
||||
[subsection "Call SILE function and packages"]
|
||||
|
||||
[subsection "Macro"]
|
||||
|
||||
Using 'def-syntax', you can add your macro to sile. the example is a "custom-section" macro:
|
||||
Using [font-family "Noto Sans Mono CJK TC" "def-syntax"], you can add your macro to sile. the example is a "custom-section" macro:
|
||||
|
||||
[font-family "Noto Sans Mono CJK TC" "123
|
||||
|
||||
124"]
|
||||
|
||||
underline
|
||||
[call noindent][font-family "Noto Sans Mono CJK TC" "[def-syntax subsection"]
|
||||
|
||||
[call noindent][font-family "Noto Sans Mono CJK TC" "[[_ x][str-append"]
|
||||
|
||||
[call noindent][font-family "Noto Sans Mono CJK TC" "[set! section-title [str-append [str-append [str sub-section-var] [str \". \" ]] [str x]]]"]
|
||||
|
||||
[call noindent][font-family "Noto Sans Mono CJK TC" "[font [[size \"16pt\"][weight \"600\"]] section-title]"]
|
||||
|
||||
[call noindent][font-family "Noto Sans Mono CJK TC" "set! sub-section-var [+ sub-section-var 1]]]]]"]
|
||||
|
||||
|
||||
|
||||
[str "underline
|
||||
bold
|
||||
italic
|
||||
font-size
|
||||
|
@ -80,7 +106,7 @@ script
|
|||
docu-para
|
||||
call
|
||||
xml-to-string
|
||||
SILE-STRING-ADD!
|
||||
|
||||
SILE
|
||||
print
|
||||
set!
|
||||
|
@ -88,17 +114,4 @@ def-syntax
|
|||
define function, closure, lambda
|
||||
str
|
||||
str-append
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
]
|
||||
% custom macro
|
||||
|
||||
|
||||
%[set! section-title [str-append [str-append [str [str \"section-var\"]] [str \". \" ]] [str x]]]
|
||||
|
||||
%[font [[size \"20pt\"][weight \"800\"]] [str \"section-title\"]]
|
||||
|
||||
%[set! [str \"section-var\"] [+ [str \"section-var\"] 1]]
|
||||
str-append-many" ]]
|
BIN
example/total-interface.png
Normal file
BIN
example/total-interface.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
|
@ -42,11 +42,11 @@ class ClochurLexer(QsciLexerCustom):
|
|||
operator_list = [ '-', '+', '*', '/', '>' ,'=','<','>=','<=']
|
||||
# SILE and SILE-STRING-ADD! is internal, so they're not added.
|
||||
function_list = ['if', 'docu', 'docu-para', 'script', 'call','xml-to-string', 'begin',
|
||||
'str','str-append','set!','print', 'define', 'def-syntax', 'lambda', 'eval','cons',
|
||||
'str','str-append', 'str-append-many','set!','print', 'define', 'def-syntax', 'lambda', 'eval','cons',
|
||||
'car','cdr','ls-ref','ls']
|
||||
self.PRIMARY = macro_list + boolean_list + operator_list + function_list
|
||||
|
||||
self.split_pattern = re.compile(r'(\s+|\\%|%|\\\[|\\\]|[[]|[]])')
|
||||
self.split_pattern = re.compile(r'(\s+|\\%|%|\\\[|\\\]|[[]|[]]|\\\"|\")')
|
||||
|
||||
font = QFont()
|
||||
font.setFamily(parent.font_family)
|
||||
|
@ -196,7 +196,6 @@ class ClochurLexer(QsciLexerCustom):
|
|||
if rainbow_state >= 10:
|
||||
new_state = self.String
|
||||
elif rainbow_state < 7:
|
||||
print("rainbow_state" + str(type(rainbow_state)) + str(rainbow_state))
|
||||
new_state = getattr(self, "Rainbow" + str(rainbow_state))
|
||||
rainbow_state = (rainbow_state + 1) % 7
|
||||
else:
|
||||
|
|
|
@ -30,11 +30,16 @@ class Interpreter:
|
|||
self.preprocessing_commands = '''[def-syntax docu
|
||||
[[_ x] [SILE[docu-aux x]]]
|
||||
[[_ x y...] [SILE[docu-aux x y...]]]]
|
||||
|
||||
|
||||
[def-syntax docu-aux
|
||||
[[_ x] [SILE-STRING-ADD![str x]]]
|
||||
[[_ [x...]] [SILE-STRING-ADD![str [x...]]]]
|
||||
[[_ x y...] [begin[docu-aux x] [docu-aux y...]]]]
|
||||
[[_ x] [str x]]
|
||||
[[_ [x...]] [str [x...]]]
|
||||
[[_ x y...] [str-append [docu-aux x] [docu-aux y...]]]]
|
||||
|
||||
[def-syntax str-append-many
|
||||
[[_ x y] [str-append x y]]
|
||||
[[_ x y z...] [str-append x [str-append-many y z...]]]]
|
||||
|
||||
[def-syntax font
|
||||
[[_ [para...] inner] [call font [para...] inner]]
|
||||
|
@ -77,6 +82,8 @@ class Interpreter:
|
|||
def remove_spaces_and_newlines_aux(self, sexp, is_inside_defstx):
|
||||
if isinstance(sexp, list):
|
||||
result = []
|
||||
if sexp == []:
|
||||
return sexp
|
||||
if isinstance(sexp[0], dict) and sexp[0]["token"] == "def-syntax":
|
||||
is_inside_defstx = True
|
||||
if isinstance(sexp[0], dict) and sexp[0]["token"] == "docu" \
|
||||
|
@ -365,6 +372,7 @@ class Interpreter:
|
|||
script_xml = ET.Element('script')
|
||||
script_xml.attrib["src"] = self.destring(sexp[1]["token"])
|
||||
self.silexml.append(script_xml)
|
||||
return ""
|
||||
|
||||
elif sexp[0]["token"] == "docu-para":
|
||||
if not len(sexp) == 2:
|
||||
|
@ -375,29 +383,42 @@ class Interpreter:
|
|||
attrib_name = i[0]["token"]
|
||||
attrib_value = self.destring(i[1]["token"])
|
||||
self.silexml.attrib[attrib_name] = attrib_value
|
||||
return ""
|
||||
|
||||
# [call callee {[[attr1 val1] [attr2 val2] ...]} {inner_val}]
|
||||
elif sexp[0]["token"] == "call":
|
||||
callee = sexp[1]["token"]
|
||||
call_xml = ET.Element(callee)
|
||||
if len(sexp) == 4 or (len(sexp) == 3 and isinstance(sexp[2], list)):
|
||||
if len(sexp) == 4 or (len(sexp) == 3 and isinstance(sexp[2], list) and isinstance(sexp[2][0], list)):
|
||||
for i in sexp[2]:
|
||||
attrib_name = i[0]["token"]
|
||||
attrib_value = self.destring(self.interprete_aux(i[1]))
|
||||
call_xml.attrib[attrib_name] = attrib_value
|
||||
if i == []:
|
||||
pass
|
||||
else:
|
||||
attrib_name = i[0]["token"]
|
||||
attrib_value = self.destring(self.interprete_aux(i[1]))
|
||||
call_xml.attrib[attrib_name] = attrib_value
|
||||
|
||||
if len(sexp) == 4:
|
||||
call_xml.text = self.destring(self.interprete_aux(sexp[3]))
|
||||
inner_text = self.destring(self.interprete_aux(sexp[3]))
|
||||
call_xml_text = ET.tostring(call_xml, encoding='unicode')
|
||||
matched = re.match(r"<("+callee+")([ ]*.*[ ]*)/>", call_xml_text)
|
||||
call_xml_head = "<" + matched.group(1) + matched.group(2) + ">"
|
||||
call_xml_tail = "</" + matched.group(1) + ">"
|
||||
call_xml_text = call_xml_head + inner_text + call_xml_tail
|
||||
|
||||
if len(sexp) == 3:
|
||||
call_xml_text = ET.tostring(call_xml,encoding='unicode')
|
||||
|
||||
self.silexml.append(call_xml)
|
||||
return SubXMLElement(call_xml)
|
||||
return call_xml_text
|
||||
elif len(sexp) == 3:
|
||||
call_xml.text = self.destring(self.interprete_aux(sexp[2]))
|
||||
self.silexml.append(call_xml)
|
||||
return SubXMLElement(call_xml)
|
||||
inner_text = self.destring(self.interprete_aux(sexp[2]))
|
||||
call_xml_head = "<"+callee+">"
|
||||
call_xml_tail = "</"+callee+">"
|
||||
call_xml_text = call_xml_head + inner_text + call_xml_tail
|
||||
|
||||
return call_xml_text
|
||||
elif len(sexp) == 2:
|
||||
self.silexml.append(call_xml)
|
||||
return SubXMLElement(call_xml)
|
||||
return ET.tostring(call_xml, encoding='unicode')
|
||||
else:
|
||||
raise Exception("Line %d, Col. %d, the form of call is mal-formed." % (sexp[0]["line"], sexp[0]["col"]))
|
||||
|
||||
|
@ -455,36 +476,43 @@ class Interpreter:
|
|||
|
||||
# if it's a sub-xml-element, show the string form of it, or return the input unchanged.
|
||||
# It's recommended to use it only print it in terminal with 'print'
|
||||
elif sexp[0]["token"] == "xml-to-string":
|
||||
if len(sexp) != 2:
|
||||
raise Exception("Line %d, Col. %d, the argument of SHOW-XML-TREE is mal-formed" % (sexp[0]["line"], sexp[0]["col"]))
|
||||
else:
|
||||
res = self.interprete_aux(sexp[1])
|
||||
if isinstance(res, SubXMLElement):
|
||||
return ET.tostring(res.element, encoding='unicode')
|
||||
else:
|
||||
return res
|
||||
#elif sexp[0]["token"] == "xml-to-string":
|
||||
# if len(sexp) != 2:
|
||||
# raise Exception("Line %d, Col. %d, the argument of SHOW-XML-TREE is mal-formed" % (sexp[0]["line"], sexp[0]["col"]))
|
||||
# else:
|
||||
# res = self.interprete_aux(sexp[1])
|
||||
# if isinstance(res, SubXMLElement):
|
||||
# return ET.tostring(res.element, encoding='unicode')
|
||||
# else:
|
||||
# return res
|
||||
|
||||
# append string to <sile>
|
||||
elif sexp[0]["token"] == "SILE-STRING-ADD!":
|
||||
subelements_found = [x for x in self.silexml.iter() if x != self.silexml]
|
||||
if subelements_found:
|
||||
if subelements_found[-1].tail == None:
|
||||
subelements_found[-1].tail = self.interprete_aux(sexp[1])
|
||||
else:
|
||||
subelements_found[-1].tail += self.interprete_aux(sexp[1])
|
||||
else:
|
||||
if self.silexml.text == None:
|
||||
self.silexml.text = self.interprete_aux(sexp[1])
|
||||
else:
|
||||
self.silexml.text += self.interprete_aux(sexp[1])
|
||||
#elif sexp[0]["token"] == "SILE-STRING-ADD!":
|
||||
# subelements_found = [x for x in self.silexml.iter() if x != self.silexml]
|
||||
# if subelements_found:
|
||||
# if subelements_found[-1].tail == None:
|
||||
# subelements_found[-1].tail = self.interprete_aux(sexp[1])
|
||||
# else:
|
||||
# subelements_found[-1].tail += self.interprete_aux(sexp[1])
|
||||
# else:
|
||||
# if self.silexml.text == None:
|
||||
# self.silexml.text = self.interprete_aux(sexp[1])
|
||||
# else:
|
||||
# self.silexml.text += self.interprete_aux(sexp[1])
|
||||
|
||||
|
||||
elif sexp[0]["token"] == "SILE":
|
||||
inner = self.interprete_aux(sexp[1])
|
||||
|
||||
return ET.tostring(self.silexml, encoding="unicode")
|
||||
orig_sile_xml = ET.tostring(self.silexml, encoding="unicode")
|
||||
matched = re.match(r'(<sile(?:.*)>.*)(</sile>)', orig_sile_xml)
|
||||
sile_before = matched.group(1)
|
||||
sile_after = matched.group(2)
|
||||
sile_xml_inserted = sile_before + inner + sile_after
|
||||
|
||||
return sile_xml_inserted
|
||||
|
||||
# applying function
|
||||
else:
|
||||
ret = self.apply(sexp)
|
||||
return ret
|
||||
|
|
|
@ -131,9 +131,14 @@ class Window(QMainWindow):
|
|||
self.about_action.triggered.connect(self.about_call)
|
||||
|
||||
self.bold_action = QAction(QIcon(":text-bold.svg"), "&Bold", self)
|
||||
self.bold_action.triggered.connect(self.bold_call)
|
||||
|
||||
self.italic_action = QAction(QIcon(":text-italic.svg"), "&Italic", self)
|
||||
self.strike_action = QAction(QIcon(":text-strikethrough.svg"), "Stri&ke", self)
|
||||
self.italic_action.triggered.connect(self.italic_call)
|
||||
|
||||
self.underline_action = QAction(QIcon(":text-underline.svg"), "&Underline", self)
|
||||
self.underline_action.triggered.connect(self.underline_call)
|
||||
|
||||
|
||||
def _createMenuBar(self):
|
||||
menuBar = QMenuBar(self)
|
||||
|
@ -192,6 +197,15 @@ class Window(QMainWindow):
|
|||
os.system('clochur')
|
||||
|
||||
def open_call(self):
|
||||
open_file = False
|
||||
if self.editor.isModified():
|
||||
reply = QMessageBox.question(self,'','Do You want to save this file before open a file? The text has been modified',
|
||||
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
self.save_as_call()
|
||||
else:
|
||||
pass
|
||||
|
||||
file_path = QFileDialog.getOpenFileName(self, 'Open file...', self.opened_file_dirname, "CLC typesetting format (*.clc)")
|
||||
if file_path[0] != '':
|
||||
self.filename = os.path.basename(file_path[0])
|
||||
|
@ -341,12 +355,29 @@ class Window(QMainWindow):
|
|||
|
||||
def select_all_call(self):
|
||||
self.editor.selectAll()
|
||||
|
||||
def bold_call(self):
|
||||
selected_text = self.editor.selectedText()
|
||||
self.editor.replaceSelectedText(f'[bold {selected_text}]')
|
||||
|
||||
def italic_call(self):
|
||||
selected_text = self.editor.selectedText()
|
||||
self.editor.replaceSelectedText(f'[italic {selected_text}]')
|
||||
|
||||
def underline_call(self):
|
||||
selected_text = self.editor.selectedText()
|
||||
self.editor.replaceSelectedText(f'[underline {selected_text}]')
|
||||
|
||||
def add_font_call(self):
|
||||
selected_text = self.editor.selectedText()
|
||||
font_family = self.font_combo_box.currentText()
|
||||
self.editor.replaceSelectedText(f'[font-family "{font_family}" {selected_text}]')
|
||||
|
||||
def about_call(self):
|
||||
|
||||
|
||||
self.about_dialog = QMessageBox.about(self, "About Clochur", __about__.version_no+"\n"+__about__.about_info)
|
||||
|
||||
|
||||
|
||||
def _createEditToolBar(self):
|
||||
editToolBar = QToolBar("Edit", self)
|
||||
|
@ -394,19 +425,20 @@ class Window(QMainWindow):
|
|||
|
||||
'''create font adder'''
|
||||
self.font_widget = QHBoxLayout()
|
||||
font_combo_box = QComboBox()
|
||||
self.font_combo_box = QComboBox()
|
||||
font_database = QFontDatabase()
|
||||
font_families = font_database.families()
|
||||
|
||||
font_combo_box.addItems(font_families)
|
||||
line_edit = font_combo_box.lineEdit()
|
||||
self.font_combo_box.addItems(font_families)
|
||||
line_edit = self.font_combo_box.lineEdit()
|
||||
#line_edit.setFont(QFont(font_combo_box.currentText(),11))
|
||||
#print(type(font_combo_box.lineEdit()).__name__)
|
||||
|
||||
font_button = QPushButton("Insert font")
|
||||
self.font_button = QPushButton("Insert font")
|
||||
|
||||
formatToolBar.addWidget(font_combo_box)
|
||||
formatToolBar.addWidget(font_button)
|
||||
formatToolBar.addWidget(self.font_combo_box)
|
||||
formatToolBar.addWidget(self.font_button)
|
||||
self.font_button.clicked.connect(self.add_font_call)
|
||||
|
||||
def generate_untitled_title(self):
|
||||
json_file = os.path.join(self.tmp_folder, self.tmp_file)
|
||||
|
|
BIN
src/example.pdf
BIN
src/example.pdf
Binary file not shown.
12
src/thirdparty/pdfjs/web/viewer.html
vendored
12
src/thirdparty/pdfjs/web/viewer.html
vendored
|
@ -227,16 +227,16 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
|
||||
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
</button>
|
||||
|
||||
<button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
|
||||
<button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
</button>
|
||||
|
||||
<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
<a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
|
|
Loading…
Reference in a new issue