예제 #1
0
    def collect_font_stats(self, container, do_embed=False):
        self.font_stats = {}
        self.font_usage_map = {}
        self.font_spec_map = {}
        self.font_rule_map = {}
        self.all_font_rules = {}

        processed_sheets = {}
        for name, is_linear in container.spine_names:
            self.font_rule_map[name] = font_face_rules = []
            resolve_property, resolve_pseudo_property, select = resolve_styles(
                container,
                name,
                sheet_callback=partial(self.collect_font_face_rules, container,
                                       processed_sheets, name))

            for rule in font_face_rules:
                self.all_font_rules[rule['src']] = rule
                if rule['src'] not in self.font_stats:
                    self.font_stats[rule['src']] = set()

            self.font_usage_map[name] = {}
            self.font_spec_map[name] = set()
            self.get_font_usage(container, name, resolve_property,
                                resolve_pseudo_property, font_face_rules,
                                do_embed)
        self.font_stats = {
            k: {safe_chr(x)
                for x in v}
            for k, v in iteritems(self.font_stats)
        }
        for fum in itervalues(self.font_usage_map):
            for v in itervalues(fum):
                v['text'] = {safe_chr(x) for x in v['text']}
예제 #2
0
파일: stats.py 프로젝트: Farb/calibre
    def collect_font_stats(self, container, do_embed=False):
        self.font_stats = {}
        self.font_usage_map = {}
        self.font_spec_map = {}
        self.font_rule_map = {}
        self.all_font_rules = {}

        processed_sheets = {}
        for name, is_linear in container.spine_names:
            self.font_rule_map[name] = font_face_rules = []
            resolve_property, resolve_pseudo_property, select = resolve_styles(container, name, sheet_callback=partial(
                self.collect_font_face_rules, container, processed_sheets, name))

            for rule in font_face_rules:
                self.all_font_rules[rule['src']] = rule
                if rule['src'] not in self.font_stats:
                    self.font_stats[rule['src']] = set()

            self.font_usage_map[name] = {}
            self.font_spec_map[name] = set()
            self.get_font_usage(container, name, resolve_property, resolve_pseudo_property, font_face_rules, do_embed)
        self.font_stats = {k:{safe_chr(x) for x in v} for k, v in self.font_stats.iteritems()}
        for fum in self.font_usage_map.itervalues():
            for v in fum.itervalues():
                v['text'] = {safe_chr(x) for x in v['text']}
예제 #3
0
파일: report.py 프로젝트: j-howell/calibre
def chars_data(container, book_locale, *args):
    cc = count_all_chars(container, book_locale)
    nmap = {n:i for i, (n, l) in enumerate(container.spine_names)}

    def sort_key(name):
        return nmap.get(name, len(nmap)), numeric_sort_key(name)

    for i, (codepoint, usage) in enumerate(iteritems(cc.chars)):
        yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), cc.counter[codepoint])
예제 #4
0
def chars_data(container, book_locale, *args):
    cc = count_all_chars(container, book_locale)
    nmap = {n: i for i, (n, l) in enumerate(container.spine_names)}

    def sort_key(name):
        return nmap.get(name, len(nmap)), numeric_sort_key(name)

    for i, (codepoint, usage) in enumerate(iteritems(cc.chars)):
        yield Char(i, safe_chr(codepoint), codepoint,
                   sorted(usage, key=sort_key), cc.counter[codepoint])
예제 #5
0
def chars_data(container, book_locale):
    chars = defaultdict(set)
    counter = Counter()
    def count(codepoint):
        counter[codepoint] += 1

    for name, is_linear in container.spine_names:
        if container.mime_map.get(name) not in OEB_DOCS:
            continue
        raw = container.raw_data(name)
        counts = Counter(ord_string(raw))
        counter.update(counts)
        for codepoint in counts:
            chars[codepoint].add(name)

    nmap = {n:i for i, (n, l) in enumerate(container.spine_names)}
    def sort_key(name):
        return nmap.get(name, len(nmap)), numeric_sort_key(name)

    for i, (codepoint, usage) in enumerate(chars.iteritems()):
        yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), counter[codepoint])
예제 #6
0
파일: report.py 프로젝트: AEliu/calibre
def chars_data(container, *args):
    chars = defaultdict(set)
    counter = Counter()
    def count(codepoint):
        counter[codepoint] += 1

    for name, is_linear in container.spine_names:
        if container.mime_map.get(name) not in OEB_DOCS:
            continue
        raw = container.raw_data(name)
        counts = Counter(ord_string(raw))
        counter.update(counts)
        for codepoint in counts:
            chars[codepoint].add(name)

    nmap = {n:i for i, (n, l) in enumerate(container.spine_names)}
    def sort_key(name):
        return nmap.get(name, len(nmap)), numeric_sort_key(name)

    for i, (codepoint, usage) in enumerate(chars.iteritems()):
        yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), counter[codepoint])
예제 #7
0
파일: text.py 프로젝트: timpalpant/calibre
 def replace_possible_unicode_sequence(self):
     c = self.textCursor()
     has_selection = c.hasSelection()
     if has_selection:
         text = unicode(c.selectedText()).rstrip("\0")
     else:
         c.setPosition(c.position() - min(c.positionInBlock(), 6), c.KeepAnchor)
         text = unicode(c.selectedText()).rstrip("\0")
     m = re.search(r"[a-fA-F0-9]{2,6}$", text)
     if m is None:
         return False
     text = m.group()
     try:
         num = int(text, 16)
     except ValueError:
         return False
     if num > 0x10FFFF or num < 1:
         return False
     end_pos = max(c.anchor(), c.position())
     c.setPosition(end_pos - len(text)), c.setPosition(end_pos, c.KeepAnchor)
     c.insertText(safe_chr(num))
     return True
예제 #8
0
 def replace_possible_unicode_sequence(self):
     c = self.textCursor()
     has_selection = c.hasSelection()
     if has_selection:
         text = unicode(c.selectedText()).rstrip('\0')
     else:
         c.setPosition(c.position() - min(c.positionInBlock(), 6), c.KeepAnchor)
         text = unicode(c.selectedText()).rstrip('\0')
     m = re.search(r'[a-fA-F0-9]{2,6}$', text)
     if m is None:
         return False
     text = m.group()
     try:
         num = int(text, 16)
     except ValueError:
         return False
     if num > 0x10ffff or num < 1:
         return False
     end_pos = max(c.anchor(), c.position())
     c.setPosition(end_pos - len(text)), c.setPosition(end_pos, c.KeepAnchor)
     c.insertText(safe_chr(num))
     return True
예제 #9
0
 def conv_code(c):
     if c.upper()[:2] in ('U+', '0X'):
         c = int(c[2:], 16)
     return safe_chr(int(c))
예제 #10
0
파일: __init__.py 프로젝트: Farb/calibre
def my_unichr(num):
    try:
        return safe_chr(num)
    except (ValueError, OverflowError):
        return u'?'
예제 #11
0
파일: __init__.py 프로젝트: zyhong/calibre
def my_unichr(num):
    try:
        return safe_chr(num)
    except (ValueError, OverflowError):
        return '?'
예제 #12
0
파일: subset.py 프로젝트: AEliu/calibre
 def conv_code(c):
     if c.upper()[:2] in ('U+', '0X'):
         c = int(c[2:], 16)
     return safe_chr(int(c))