Exemple #1
0
 def glyph(self, glyph, extend=None):
     '''Return TypeRig proxy glyph object (pGlyph) by index (int) or name (str).'''
     if isinstance(glyph, int) or isinstance(glyph, basestring):
         return pGlyph(self.fg,
                       self.fg[glyph]) if extend is None else extend(
                           self.fg, self.fg[glyph])
     else:
         return pGlyph(self.fg, glyph) if extend is None else extend(
             self.fg, self.fg[glyph])
Exemple #2
0
    def tag_glyphs(self, mode):
        # - Init
        new_tags = self.edt_tagString.text.replace(' ', '').split(',')

        # - Helper
        def tag(glyph, tagList):
            glyph.setTags(tagList)
            glyph.updateObject(
                glyph.fl, 'Glyph: %s; Add tags: %s ' % (glyph.name, tagList))
            glyph.update()

        # - Process
        if mode == 'G':
            glyph = eGlyph()
            tag(glyph, new_tags)

        else:
            process_glyphs = []

            if mode == 'W':
                process_glyphs = [
                    pGlyph(glyph)
                    for glyph in pWorkspace().getTextBlockGlyphs()
                ]

            elif mode == 'S':
                process_glyphs = pFont().selected_pGlyphs()

            for glyph in process_glyphs:
                tag(glyph, new_tags)

        self.edt_tagString.clear()
Exemple #3
0
    def table_populate(self, mode):
        def check_type(layer):
            if layer.isMaskLayer: return 'Mask'
            if layer.isMasterLayer: return 'Master'
            if layer.isService: return 'Service'

        if fl6.CurrentFont() is not None and fl6.CurrentGlyph() is not None:
            active_font = pFont()
            active_glyph = pGlyph()

            if mode == 0:
                init_data = [(layer.name, check_type(layer))
                             for layer in active_glyph.layers()
                             if '#' not in layer.name]
            else:
                init_data = [(master, 'Master')
                             for master in active_font.pMasters.names]

            table_dict = {
                n: OrderedDict(zip(column_names, data))
                for n, data in enumerate(init_data)
            }
            self.tab_masters.clear()
            self.tab_masters.setTable(table_dict,
                                      color_dict=color_dict,
                                      enable_check=True)
Exemple #4
0
    def setStem(self, horizontal=False):
        font = pFont()
        active_glyph = pGlyph()
        selection = active_glyph.selectedNodes(None, True)

        if horizontal:
            stem_width = int(abs(selection[0].y - selection[-1].y))
        else:
            stem_width = int(abs(selection[0].x - selection[-1].x))

        stem_name = '{}.{}:{}'.format(['V', 'H'][horizontal],
                                      active_glyph.name, stem_width)
        stem_type = self.cmb_select_stem.currentIndex

        font.setStem(stem_width, stem_name, horizontal, stem_type)

        font.updateObject(
            font.fl, 'Set Stem(s): {}; {}; {}.'.format(
                stem_name, stem_width, self.cmb_select_stem.currentText))
Exemple #5
0
	def update_table_hightlights(self, search_field=False, hide_others=False):
		# !!! TODO: Use direct Vertical/Horizontal header indexing if columns/rows are moved
		show_items = []
		hidden_rows = 0

		font_layers, font_kerning, all_pairs = self.data_fontKerning
		col = font_layers.index(pGlyph().layer().name)
		proxy_kerning = pKerning(font_kerning[col])
		
		self.tab_fontKerning.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
		self.tab_fontKerning.clearSelection()

		if not search_field: 
			pairs_list = [self.application.getActiveKernPair()]
		else:
			pairs_list = parser_highlight(self.edt_search_pair.text)

		for pair in pairs_list:
			if pair is not None:
				left, right = pair
				new_left, new_right = proxy_kerning.getPairGroups((left, right))
				row = all_pairs.index((new_left, new_right))
				
				selected_item = self.tab_fontKerning.item(row, col)
				show_items.append(row)
				
				if not search_field:
					self.tab_fontKerning.setRangeSelected(QtGui.QTableWidgetSelectionRange(row, col, row, col), True)
					self.tab_fontKerning.scrollToItem(selected_item, QtGui.QAbstractItemView.PositionAtCenter)
				else:
					self.tab_fontKerning.selectRow(row)

		if self.btn_search_hide.isChecked():
			for row in xrange(self.tab_fontKerning.rowCount):
				if row in show_items:
					self.tab_fontKerning.showRow(row)
				else:	
					self.tab_fontKerning.hideRow(row)
					hidden_rows += 1

		self.lbl_status_pairs_hidden.setText(hidden_rows)
		self.tab_fontKerning.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) # Back to regular selection
Exemple #6
0
	def __init__(self):
		super(tool_tab, self).__init__()

		# - Init
		temp = pGlyph()
		self.active_font = pFont()
		layer_names = [layer.name for layer in temp.layers() if '#' not in layer.name]
		
		# - Widgets
		# -- Progress bar
		self.progress = QtGui.QProgressBar()
		self.progress.setMaximum(100)

		# -- Report Tree
		self.audit_report = OrderedDict(empty_record)
		self.header_names = ['Glyph', 'Layers']
		self.audit_tree = TRWAuditTree(self.audit_report, self.header_names)
		self.audit_tree.selectionModel().selectionChanged.connect(self.auto_preview)
		
		# -- Test List
		temp_audit_glyph = auditGlyph(temp.fg, self.active_font.fg, self.audit_report)
		audit_tests = [test.replace('_', ' ').replace('audit', '').title() for test in temp_audit_glyph.get_all_tests()]

		self.audit_list = QtGui.QListWidget()
		self.audit_list.setAlternatingRowColors(True)
		self.audit_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
		self.audit_list.addItems(audit_tests)

		# -- Audit Options
		self.cmb_layers = CheckableComboBox()
		self.cmb_layers.addItems(['All Masters'] + layer_names)
		
		self.cmb_reference = QtGui.QComboBox()
		self.cmb_reference.addItems(layer_names)
		
		if 'Regular' in layer_names:
			self.cmb_reference.setCurrentIndex(layer_names.index('Regular'))

		# -- Action Buttons
		self.btn_audit_run = QtGui.QPushButton('Process Entire Font')
		self.btn_audit_glyphs = QtGui.QPushButton('Process Glyph Selection')
		self.btn_audit_tests = QtGui.QPushButton('Selected tests only')
		self.btn_audit_reset = QtGui.QPushButton('Reset Record')
		self.btn_audit_save = QtGui.QPushButton('Save Record')
		self.btn_audit_select = QtGui.QPushButton('Auto Select Glyphs')
		self.btn_select_cheked = QtGui.QPushButton('Select Checked Glyphs')
		
		self.btn_audit_select.setCheckable(True)
		self.btn_audit_tests.setCheckable(True)
		self.btn_audit_select.setChecked(False)
		self.btn_audit_tests.setChecked(True)

		self.btn_audit_run.clicked.connect(lambda: self.process_audit(False))
		self.btn_audit_glyphs.clicked.connect(lambda: self.process_audit(True))
		self.btn_select_cheked.clicked.connect(lambda: self.selected_preview())

		self.btn_audit_reset.clicked.connect(self.reset)
		self.btn_audit_save.clicked.connect(self.save_audit)
		
		# - Build Layout
		lay_main = QtGui.QVBoxLayout()
		lay_audit = QtGui.QGridLayout()
		lay_audit.addWidget(self.btn_audit_tests, 				 0,  0,  1,  2)
		lay_audit.addWidget(self.btn_audit_select, 				 0,  2,  1,  2)
		lay_audit.addWidget(self.btn_select_cheked, 			 0,  4,  1,  2)
		
		lay_audit.addWidget(self.btn_audit_save, 				 0,  6,  1,  2)
		lay_audit.addWidget(self.btn_audit_reset, 				 0,  8,  1,  2)
		lay_audit.addWidget(self.btn_audit_glyphs, 				 0,  10,  1, 2) 
		lay_audit.addWidget(self.btn_audit_run, 				 0, 12,  1,  4) 
		lay_audit.addWidget(QtGui.QLabel('Audit Tests:'),		 1,  0,  1,  4)
		lay_audit.addWidget(self.audit_list, 					 2,  0, 21,  4) 
		lay_audit.addWidget(QtGui.QLabel('Audit Report:'),		 1,  4,  1, 12)
		lay_audit.addWidget(self.audit_tree, 					 2,  4, 23, 12)
		lay_audit.addWidget(QtGui.QLabel('Reference:'),			23,  0,  1,  1)
		lay_audit.addWidget(self.cmb_reference, 				23,  1,  1,  3)
		lay_audit.addWidget(QtGui.QLabel('Audit on:'),			24,  0,  1,  1)
		lay_audit.addWidget(self.cmb_layers, 					24,  1,  1,  3)
		lay_audit.addWidget(self.progress, 						25,  0,  1,  16)

		# - Finish
		lay_main.addLayout(lay_audit)
		self.setLayout(lay_main)
		self.setMinimumSize(300, self.sizeHint.height())
Exemple #7
0
    def __init__(self):
        super(TRDropGuide, self).__init__()

        # -- Editing fields
        self.edt_guideName = QtGui.QLineEdit()
        self.edt_guideName.setPlaceholderText('New Guideline')

        self.edt_guideTag = TRGLineEdit()
        self.edt_guideTag.setPlaceholderText('Tag')

        self.edt_sourceName = QtGui.QLineEdit()
        self.edt_sourceName.setPlaceholderText('Source name / Current')
        self.edt_sourceName.setToolTip(
            'Source glyph name, or Active Glyph if Blank')

        # -- Combo box
        self.cmb_select_V = QtGui.QComboBox()
        self.cmb_select_H = QtGui.QComboBox()
        self.cmb_select_color = QtGui.QComboBox()

        self.cmb_select_V.addItems(['BBox width', 'Adv. width'])
        self.cmb_select_H.addItems([
            'BBox height', 'X-Height', 'Caps Height', 'Ascender', 'Descender',
            'Adv. height'
        ])

        colorNames = QtGui.QColor.colorNames()
        for i in range(len(colorNames)):
            self.cmb_select_color.addItem(colorNames[i])
            self.cmb_select_color.setItemData(i, QtGui.QColor(colorNames[i]),
                                              QtCore.Qt.DecorationRole)

        self.cmb_select_color.setCurrentIndex(colorNames.index('red'))

        self.cmb_select_color.setMinimumWidth(40)
        self.edt_guideName.setMinimumWidth(40)
        self.edt_guideTag.setMinimumWidth(40)

        # -- SpinBox
        self.spb_prc_V = QtGui.QSpinBox()
        self.spb_prc_V.setMaximum(300)
        self.spb_prc_V.setSuffix('%')
        self.spb_prc_V.setMinimumWidth(45)

        self.spb_prc_H = QtGui.QSpinBox()
        self.spb_prc_H.setMaximum(300)
        self.spb_prc_H.setSuffix('%')
        self.spb_prc_H.setMinimumWidth(45)

        self.spb_unit_V = QtGui.QSpinBox()
        self.spb_unit_V.setMaximum(300)
        self.spb_unit_V.setMinimum(-300)
        self.spb_unit_V.setSuffix(' U')
        self.spb_unit_V.setMinimumWidth(45)

        self.spb_unit_H = QtGui.QSpinBox()
        self.spb_unit_H.setMaximum(300)
        self.spb_unit_H.setMinimum(-300)
        self.spb_unit_H.setSuffix(' U')
        self.spb_unit_H.setMinimumWidth(45)

        # -- Button
        self.btn_dropGuide = QtGui.QPushButton('&Drop')
        self.btn_dropFlipX = QtGui.QPushButton('Drop: Flip &X')
        self.btn_dropFlipY = QtGui.QPushButton('Drop: Flip &Y')
        self.btn_dropLayer_V = QtGui.QPushButton('Vertical')
        self.btn_dropLayer_H = QtGui.QPushButton('Horizontal')
        self.btn_getName = QtGui.QPushButton('Get &Name')

        self.btn_dropGuide.setToolTip(
            'Drop guideline between any two selected nodes.\nIf single node is selected a vertical guide is\ndropped (using the italic angle if present).'
        )
        self.btn_dropFlipX.setToolTip(
            'Drop flipped guideline between any two selected nodes.')
        self.btn_dropFlipY.setToolTip(
            'Drop flipped guideline between any two selected nodes.')
        self.btn_getName.setToolTip('Get the name of the current active glyph')

        self.btn_dropGuide.clicked.connect(lambda: self.drop_guide_nodes(
            (1, 1)))
        self.btn_dropFlipX.clicked.connect(lambda: self.drop_guide_nodes(
            (-1, 1)))
        self.btn_dropFlipY.clicked.connect(lambda: self.drop_guide_nodes(
            (1, -1)))
        self.btn_getName.clicked.connect(
            lambda: self.edt_sourceName.setText(pGlyph().name))
        self.btn_dropLayer_V.clicked.connect(self.drop_guide_V)
        self.btn_dropLayer_H.clicked.connect(self.drop_guide_H)

        # - Build
        self.addWidget(QtGui.QLabel('Name:'), 1, 0, 1, 4)
        self.addWidget(QtGui.QLabel('Tag:'), 1, 4, 1, 4)
        self.addWidget(QtGui.QLabel('Color:'), 1, 8, 1, 4)
        self.addWidget(self.edt_guideName, 2, 0, 1, 4)
        self.addWidget(self.cmb_select_color, 2, 8, 1, 4)
        self.addWidget(self.edt_guideTag, 2, 4, 1, 4)
        self.addWidget(QtGui.QLabel('Selected Nodes:'), 3, 0, 1, 9)
        self.addWidget(self.btn_dropGuide, 4, 0, 1, 4)
        self.addWidget(self.btn_dropFlipX, 4, 4, 1, 4)
        self.addWidget(self.btn_dropFlipY, 4, 8, 1, 4)
        self.addWidget(QtGui.QLabel('Glyph Layer:'), 5, 0, 1, 4)
        self.addWidget(self.edt_sourceName, 6, 0, 1, 8)
        self.addWidget(self.btn_getName, 6, 8, 1, 4)
        self.addWidget(self.cmb_select_V, 7, 0, 1, 4)
        self.addWidget(self.spb_prc_V, 7, 4, 1, 2)
        self.addWidget(self.spb_unit_V, 7, 6, 1, 2)
        self.addWidget(self.btn_dropLayer_V, 7, 8, 1, 4)
        self.addWidget(self.cmb_select_H, 8, 0, 1, 4)
        self.addWidget(self.spb_prc_H, 8, 4, 1, 2)
        self.addWidget(self.spb_unit_H, 8, 6, 1, 2)
        self.addWidget(self.btn_dropLayer_H, 8, 8, 1, 4)
Exemple #8
0
    def process_cleanup(self, mode):
        # - Init
        process_layers = self.active_font.masters()
        process_glyphs = self.active_font.glyphs()
        temp_glyph_mark = self.color_codes[self.cmb_select_color.currentText]
        remove_glyphs = []

        # - Set progress bar
        all_glyph_counter = 0
        self.progress.setValue(all_glyph_counter)
        glyph_count = len(process_glyphs)

        for fg_glyph in process_glyphs:
            # - Init
            glyph = pGlyph(fg_glyph, self.active_font.fg)

            # - Remove auto layers, tags and labels
            if mode == 'auto':
                # - Cleanup
                # -- Remove Font Notes
                glyph.fl.note = ''

                # -- Remove Auto Layers
                for layer_name in process_layers:
                    if glyph.layer(layer_name).autoLayer:
                        glyph.layer(layer_name).autoLayer = False

                # -- Remove unnecessary tags
                if search_name in glyph.name and glyph.name.count(
                        glyph_suffix_separator) > 1:
                    new_tags = []

                    for tag in glyph.tags:
                        match = re.search(search_tag, tag)
                        if not bool(match):
                            new_tags.append(tag)

                    glyph.tags = new_tags

            # - Remove temporary glyphs with some user defined mark
            if mode == 'temp':
                if glyph.mark == temp_glyph_mark:
                    remove_glyphs.append(glyph.name)

            # - Set progress
            all_glyph_counter += 1
            current_progress = all_glyph_counter * 100 / glyph_count
            self.progress.setValue(current_progress)

        # - Remove glyphs from font
        self.active_font.fg.clearMaps()
        success = 0

        if (mode == 'temp' or mode == 'unic') and len(remove_glyphs):
            for glyph_name in reversed(remove_glyphs):
                ret = self.active_font.fg.removeGlyph(glyph_name)
                if ret: success += 1

            output(
                0, app_name, 'Font: %s; Glyphs to remove: %s; Success: %s' %
                (self.active_font.name, len(remove_glyphs), success))

        output(0, app_name,
               'Font: %s; Cleanup Finished!' % self.active_font.name)
        self.active_font.update()
        self.progress.setValue(0)
Exemple #9
0
    def __init__(self):
        super(SGPreflight, self).__init__()

        # - Init
        temp = pGlyph()
        self.active_font = pFont()
        layer_names = [
            layer.name for layer in temp.layers() if '#' not in layer.name
        ]

        # - Automat
        self.auto_fl = Automat()

        # - Widgets
        # - Combo Boxes
        self.cmb_select_color = QtGui.QComboBox()
        self.color_codes = {
            name: value
            for name, value, discard in fontMarkColors
        }

        for i in range(len(fontMarkColors)):
            self.cmb_select_color.addItem(fontMarkColors[i][0])
            self.cmb_select_color.setItemData(
                i, QtGui.QColor(fontMarkColors[i][2]),
                QtCore.Qt.DecorationRole)

        # -- Boxes
        self.box_preflight = QtGui.QGroupBox('Font Preflight:')
        self.box_audit = QtGui.QGroupBox('Font Audit:')

        # -- Progress bar
        self.progress = QtGui.QProgressBar()
        self.progress.setMaximum(100)

        # -- Report Tree
        self.audit_report = OrderedDict(empty_record)
        self.header_names = ['Glyph', 'Layers']
        self.audit_tree = TRWAuditTree(self.audit_report, self.header_names)
        self.audit_tree.selectionModel().selectionChanged.connect(
            self.auto_preview)

        # -- Action Buttons
        # --- Preflight
        self.btn_preflight_info = QtGui.QPushButton('Edit Font Info')
        self.btn_preflight_audit = QtGui.QPushButton('Audit Font')
        self.btn_preflight_clean = QtGui.QPushButton(
            'Cleanup auto layers, unused tags and labels')
        self.btn_preflight_clean_flag = QtGui.QPushButton(
            'Remove glyphs marked with:')
        self.btn_preflight_actions = QtGui.QPushButton('Open Actions')
        self.btn_preflight_save = QtGui.QPushButton('Save Font')
        self.btn_preflight_export = QtGui.QPushButton('Export Font')

        self.btn_preflight_info.clicked.connect(
            lambda n: self.auto_fl.run('Font_Info'))
        self.btn_preflight_actions.clicked.connect(
            lambda n: self.auto_fl.run('Action'))
        self.btn_preflight_save.clicked.connect(
            lambda n: self.auto_fl.run('SaveFontAs'))
        self.btn_preflight_export.clicked.connect(
            lambda n: self.auto_fl.run('Export_Fonts'))
        self.btn_preflight_clean.clicked.connect(
            lambda: self.process_cleanup(mode='auto'))
        self.btn_preflight_clean_flag.clicked.connect(
            lambda: self.process_cleanup(mode='temp'))

        # --- Audit
        self.btn_audit_reset = QtGui.QPushButton('Reset Record')
        self.btn_audit_select = QtGui.QPushButton('Auto Select Glyphs')
        self.btn_audit_select.setCheckable(True)
        self.btn_audit_select.setChecked(False)
        self.btn_preflight_audit.clicked.connect(self.process_audit)
        self.btn_audit_reset.clicked.connect(self.reset)

        # - Build Layout
        lay_main = QtGui.QVBoxLayout()
        lay_preflight = QtGui.QGridLayout()
        lay_preflight.addWidget(QtGui.QLabel('1: Update font info: version.'),
                                0, 0, 1, 4)
        lay_preflight.addWidget(self.btn_preflight_info, 1, 0, 1, 4)
        lay_preflight.addWidget(
            QtGui.QLabel('2: Audit Font for known glyph problems.'), 2, 0, 1,
            4)
        lay_preflight.addWidget(self.btn_preflight_audit, 3, 0, 1, 4)
        lay_preflight.addWidget(QtGui.QLabel('3: Cleanup Font:'), 4, 0, 1, 4)
        lay_preflight.addWidget(self.btn_preflight_clean, 5, 0, 1, 4)
        lay_preflight.addWidget(self.btn_preflight_clean_flag, 7, 0, 1, 2)
        lay_preflight.addWidget(self.cmb_select_color, 7, 2, 1, 2)
        lay_preflight.addWidget(
            QtGui.QLabel(
                '4: All glyphs/masters: Apply rounding; Decompose; Convert to TT curves.'
            ), 8, 0, 1, 4)
        lay_preflight.addWidget(self.btn_preflight_actions, 9, 0, 1, 4)
        lay_preflight.addWidget(QtGui.QLabel('5: Save your work.'), 10, 0, 1,
                                4)
        lay_preflight.addWidget(self.btn_preflight_save, 11, 0, 1, 4)
        lay_preflight.addWidget(QtGui.QLabel('6: Export fonts.'), 12, 0, 1, 4)
        lay_preflight.addWidget(self.btn_preflight_export, 13, 0, 1, 4)
        self.box_preflight.setLayout(lay_preflight)

        lay_audit = QtGui.QGridLayout()
        lay_audit.addWidget(self.btn_audit_select, 0, 6, 1, 3)
        lay_audit.addWidget(self.btn_audit_reset, 0, 9, 1, 3)
        lay_audit.addWidget(QtGui.QLabel('Audit Report:'), 1, 6, 1, 6)
        lay_audit.addWidget(self.audit_tree, 2, 6, 20, 6)
        self.box_audit.setLayout(lay_audit)

        lay_split = QtGui.QHBoxLayout()
        lay_split.addWidget(self.box_preflight)
        lay_split.addWidget(self.box_audit)
        lay_main.addLayout(lay_split)
        lay_main.addWidget(self.progress)
        self.setLayout(lay_main)

        # - Finish
        self.setMinimumSize(300, self.sizeHint.height())