def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = SyntaxTextCharFormat() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] elif last < len(text): ans.append((len(text) - last, fmt)) if tprefs[ 'inline_spell_check'] and state.tags and user_data.tag_ok_for_spell( state.tags[-1].name) and hasattr(dictionaries, 'active_user_dictionaries'): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = SyntaxTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: ctext = text[tpos:tpos + tlen] ppos = 0 for start, length in split_into_words_and_positions( ctext, lang=locale.langcode): if start > ppos: split_ans.append((start - ppos, fmt)) ppos = start + length recognized = dictionaries.recognized( ctext[start:ppos], locale) if not recognized: wsfmt = SyntaxTextCharFormat(sfmt) wsfmt.setProperty(SPELL_PROPERTY, (ctext[start:ppos], locale)) split_ans.append((length, fmt if recognized else wsfmt)) if ppos < tlen: split_ans.append((tlen - ppos, fmt)) tpos += tlen ans = split_ans return ans
def mark_nbsp(state, text, nbsp_format): ans = [] fmt = None if state.bold or state.italic: fmt = SyntaxTextCharFormat() if state.bold: fmt.setFontWeight(QFont.Bold) if state.italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) if not ans: ans = [(len(text), fmt)] return ans
def highlight_to_char_format(h): ans = SyntaxTextCharFormat() if h.bold: ans.setFontWeight(QFont.Bold) if h.italic: ans.setFontItalic(True) if h.fg is not None: ans.setForeground(h.fg) if h.bg is not None: ans.setBackground(h.bg) if h.underline: ans.setUnderlineStyle(underline_styles[h.underline]) if h.underline_color is not None: ans.setUnderlineColor(h.underline_color.color()) return ans
def highlight_to_char_format(h): ans = SyntaxTextCharFormat() if h.bold: ans.setFontWeight(QFont.Bold) if h.italic: ans.setFontItalic(True) if h.fg is not None: ans.setForeground(h.fg) if h.bg is not None: ans.setBackground(h.bg) if h.underline is not None: ans.setUnderlineStyle(underline_styles[h.underline]) if h.underline_color is not None: ans.setUnderlineColor(h.underline_color.color()) return ans
def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = SyntaxTextCharFormat() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] elif last < len(text): ans.append((len(text) - last, fmt)) if tprefs['inline_spell_check'] and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name) and hasattr(dictionaries, 'active_user_dictionaries'): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = SyntaxTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: ctext = text[tpos:tpos+tlen] ppos = 0 for start, length in split_into_words_and_positions(ctext, lang=locale.langcode): if start > ppos: split_ans.append((start - ppos, fmt)) ppos = start + length recognized = dictionaries.recognized(ctext[start:ppos], locale) if not recognized: wsfmt = SyntaxTextCharFormat(sfmt) wsfmt.setProperty(SPELL_PROPERTY, (ctext[start:ppos], locale)) split_ans.append((length, fmt if recognized else wsfmt)) if ppos < tlen: split_ans.append((tlen - ppos, fmt)) tpos += tlen ans = split_ans return ans
def mark_nbsp(state, text, nbsp_format): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = SyntaxTextCharFormat() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] return ans