def __init__ (self, posSize, selectionCallback=None, sizeStyle='big'): xw, yw, tx, ty = posSize self.glyphsToDisplay = [] self.keyGlyph = None self.font = None self.hashKernDic = None self.direction = 'L' self.showSelected = False self.groupIsEmpty = False self.diffMarginsInGroup = False self.groupname = None self.keyGlyph = None self.keyGlyphMargin = None self.showInfo = True self.excGlyphL = None self.excGlyphR = None self.kernValue = 0 self.darkmode = KERNTOOL_UI_DARKMODE self.darkmodeWarm = KERNTOOL_UI_DARKMODE_WARMBACKGROUND self._alpha = .1 self._scalefactorUI = .045 # sizeStyle = 'regular' ty = 85 if sizeStyle == 'big': self._scalefactorUI = .065 ty = 100 elif sizeStyle == 'small': self._scalefactorUI = .035 ty = 65 elif sizeStyle == 'mini': self._scalefactorUI = .025 ty = 45 elif sizeStyle == 'micro': self._scalefactorUI = .015 ty = 30 self.heightOfControl = ty self._selectionCallback = selectionCallback self._selfHeight = ty self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.infoLine = Canvas((0, 0, -0, -0), delegate = self, # canvasSize = (ty, ty), hasHorizontalScroller = False, hasVerticalScroller = False, autohidesScrollers = True, backgroundColor = NSColor.whiteColor(), # acceptMouseMoved = True ) self.infoLine.scrollView.getNSScrollView().setBorderType_(NSNoBorder)
def __init__(self, posSize, interface): super(GlyphLayers, self).__init__(posSize) self.ui = interface self.storageGlyph = None self.storageGlyphName = "" self.StorageGlyphCurrentLayer = "" self.jumpTo = SearchBox((0,0,165,20), placeholder = "Char/Name", sizeStyle = "small", callback = self._jumpTo_callback ) self.displayGlyphset_settingList = ['find Char/Name', "Sort by key"] self.displaySettings = 'find Char/Name' self.displayGlyphset_setting = PopUpButton((170, 0, 200, 20), self.displayGlyphset_settingList, sizeStyle = "small", callback = self._displayGlyphset_setting_callback) self.glyphset = [] self.glyphset_List = List((0,20,165,-200), self.glyphset, columnDescriptions = [ {"title": "Char", "width" : 30}, {"title": "Name", "width" : 105}, ], drawFocusRing=False, selectionCallback = self._glyphset_List_selectionCallback, ) self.set_glyphset_List() self.layersCanvas = Canvas((165,20,-0,-200), delegate=LayersCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False) slider = SliderListCell(minValue = 0, maxValue = 1000) self.slidersValuesList = [] self.sliderList = List((0,-190,350,-0),self.slidersValuesList, columnDescriptions = [{"title": "Layer" }, {"title": "Values", "cell": slider}], editCallback = self._sliderList_editCallback, drawFocusRing = False, allowsMultipleSelection = False) self.layersPreviewCanvas = Canvas((350,-190,-0,-0), delegate=LayersPreviewCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False)
def __init__(self, posSize, selectionCallback=None, window=None): xw, yw, tx, ty = posSize self._window = window self._linesToDisplay = [] # self._font = None self._fontMenu = [] self._viewArray = [] self._selectedLine = 0 self._positionYselected = 0 self._lineSize = 1800 # 1800 # 1800=1000upm; 2400=2000upm self.Ygap = 0 # - yw*2 self.shiftX = 150 self._scalefactorUI = .03 self.scaleStep = 1.2 self.lineCount = 0 self.maxX = 0 self.maxXX = 0 self._lastGlyphXpos = 0 self._selectionCallback = selectionCallback self.showselection = False self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.canvas = Canvas( (0, 0, -0, -0), delegate=self, # canvasSize = (100, 101), hasHorizontalScroller=False, hasVerticalScroller=True, autohidesScrollers=False, backgroundColor=NSColor.whiteColor(), drawsBackground=True, # acceptsMouseMoved = True ) self.canvas.scrollView.getNSScrollView().setBorderType_(NSNoBorder) fonts = AllFonts() for font in fonts: if font.info.familyName and font.info.styleName: # print font.info.familyName # print font.info.styleName self.addMenuItem(font=font, title=font.info.familyName + ' ' + font.info.styleName) self.compileLines() # print self.w.menu._viewArray self.canvas.update() self.scrollToLine(0)
def __init__(self): self.f = CurrentFont() self.letters = "" self.facet = 5 self.w = FloatingWindow((1500, 600), "Preview Facet") self.w.inputText = EditText((10, 10, 500, 24), text=self.letters, callback=self.inputTextCallback) self.w.facetSlider = Slider((520, 10, 500, 24), minValue=2, maxValue=9, value=self.facet, tickMarkCount=10, stopOnTickMarks=True, callback=self.facetSliderCallback) self.w.canvas = Canvas((10, 50, -10, -10), canvasSize=(1500, 550), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=self) addObserver(self, "updateFont", "fontBecameCurrent") self.setUpBaseWindowBehavior() self.w.open()
def buildUI(self): self.w = Window((300, 415)) self.w.currentHeightText = TextBox( (10, 10, 150, 17), "Current height: " + str(currentHeight)) self.w.currentUPM = TextBox((200, 10, -10, 17), "UPM: " + str(upm), alignment="right") self.w.targetHeightSlider = Slider((10, 40, -10, 23), minValue=currentHeight * .5, maxValue=currentHeight * 1.5, value=currentHeight, callback=self.sliderCallback) self.w.targetHeightText = TextBox((10, 82, 100, 17), "Target height:") self.w.targetHeightInput = EditText( (115, 80, 55, 21), currentHeight, callback=self.targetHeightInputCallback) self.w.okButton = Button((10, 105, -10, 40), "Scale-a-mooch!", callback=self.okButtonCallback) self.w.canvas = Canvas((0, 150, 0, 0), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=self)
def __init__(self, posSize, interface): super(GlyphSet, self).__init__(posSize) self.ui = interface self.jumpTo = SearchBox( (0, 0, 165, 20), placeholder="Char/Name", sizeStyle="small", callback=self._jumpTo_callback, # continuous = False, ) self.glyphset_List = List( (0, 20, 165, -0), [], columnDescriptions=[ { "title": "Char", "width": 30 }, { "title": "Name", "width": 105 }, ], drawFocusRing=False, selectionCallback=self._glyphset_List_selectionCallback, doubleClickCallback=self._glyphset_List_doubleClickCallback) self.displayGlyphset_settingList = ['find Char/Name', "Sort by key"] self.displaySettings = 'find Char/Name' self.displayGlyphset_setting = PopUpButton( (170, 0, 200, 20), self.displayGlyphset_settingList, sizeStyle="small", callback=self._displayGlyphset_setting_callback) self.set_glyphset_List() self.canvas = Canvas((165, 20, -0, -0), delegate=CurrentGlyphCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False)
def __init__(self): self.size = 0.25 self.w = Window((400, 400)) self.w.slider = Slider((10, 5, -10, 22), minValue=0.1, maxValue=0.4, value=self.size, callback=self.sliderCallback) self.w.canvas = Canvas((10, 30, -10, -10), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=self) self.w.open()
def __init__(self): self.f = CurrentFont() self.letters = "" self.facet = 5 self.scale = 0.25 self.w = FloatingWindow((1200, 600), "Preview Facet") self.w.inputText = GlyphSequenceEditText( (10, 10, 500, 24), self.f.naked(), callback=self.inputTextCallback) self.w.facetSlider = Slider((520, 10, 250, 24), minValue=2, maxValue=9, value=self.facet, tickMarkCount=10, stopOnTickMarks=True, callback=self.facetSliderCallback) self.w.scaleSlider = Slider((800, 10, 250, 24), minValue=0, maxValue=0.5, value=self.scale, callback=self.scaleSliderCallback) self.w.drawButton = Button((1070, 10, 120, 24), title="Make Glyphs", callback=self.drawButtonCallback) # self.w.canvas = DrawView((10, 50, -10, -10)) self.w.canvas = Canvas((10, 50, -10, -10), canvasSize=(1500, 550), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=self) addObserver(self, "updateFont", "fontBecameCurrent") self.setUpBaseWindowBehavior() # self.updateCanvas() self.w.open()
def buildUI(self): self.w = Window((500, 410), "Underline all your glyphs!") self.w.offsetText = TextBox((10, 10, -10, 20), "Offset") self.w.offsetValue = EditText((100, 8, 50, 22), self.offset, callback = self.offsetValueCallback) self.w.offsetSlider = Slider((10, 25, -10, 40), minValue = 0, maxValue = 500, value = 250, callback = self.offsetSliderCallback) self.w.thicknessText = TextBox((10, 70, -10, 20), "Thickness") self.w.thicknessValue = EditText((100, 68, 50, 22), self.thickness, callback = self.thicknessValueCallback) self.w.thicknessSlider = Slider((10, 85, -10, 40), minValue = 0, maxValue = 500, value = 250, callback = self.thicknessSliderCallback) self.w.drawButton = Button((10, 115, -10, 40), "Underline", callback = self.drawButtonCallback) self.w.canvas = Canvas((10, 160, -10, -43), hasHorizontalScroller = False, hasVerticalScroller = False, delegate = self) self.w.inputString = EditText((10, 375, -10, 24), callback = self.inputStringCallback)
def buildUI(self): x = 10 xText = 8 row1 = 10 row2 = 78 row3 = 165 row4 = 250 self.w = Window((960,590), minSize = (830,500), title = "Etch-A-Sketch: " + fontName) self.w.fontNameText = EditText((x, row1, 150, 22), fontName, callback = self.fontNameTextCallback) self.w.fontRef = CheckBox((x+160, row1, 40, 22), "Ref", callback = self.fontRefCallback) self.w.xHeightText = TextBox((xText, row2, 200, 17), "x-Height (in.)") self.w.xHeightSlider = Slider((x+2, row2+22, 194, 23), minValue = 0.5, maxValue = 2, value = self.xHeightDrawing / ppi, tickMarkCount = 7, stopOnTickMarks = True, callback = self.xHeightSliderCallback) self.w.xHeightMinVal = TextBox((xText, row2+48, 50, 17), "0.5") self.w.xHeightMidVal = TextBox((xText+85, row2+48, 50, 17), "1.25") self.w.xHeightMaxVal = TextBox((xText+177, row2+48, 50, 17), "2.0") self.w.guidesText = TextBox((xText, row3, 100, 17), "Guides") self.w.ascenderCheckbox = CheckBox((x, row3+20, 100, 22), "Ascender", callback = self.ascenderCheckboxCallback) self.w.ascenderText = EditText((x+100, row3+20, 50, 22), ascender, callback = self.ascenderTextCallback) self.w.descenderCheckbox = CheckBox((x, row3+45, 100, 22), "Descender", callback = self.descenderCheckboxCallback) self.w.descenderText = EditText((x+100, row3+45, 50, 22), descender, callback = self.descenderTextCallback) self.w.extrasText = TextBox((xText, row4, 100, 17), "Extras") self.w.blueLinesCheckbox = CheckBox((x, row4+20, 150, 22), "Non-photo blue lines", callback = self.blueLinesCheckboxCallback) self.w.grayLettersCheckbox = CheckBox((x, row4+42, 150, 22), "Gray letters", callback = self.grayLettersCheckboxCallback) self.w.printButton = SquareButton((x, 430, 200, -10), "Print!\n(cmd + p)", callback = self.printButtonCallback) self.w.printButton.bind('p', ["command"]) #self.w.canvas = DrawView((220, 10, -10, -10)) self.w.canvas = Canvas((220, 10, -10, -10), delegate=self, canvasSize=(pageWidth, pageHeight), hasHorizontalScroller=False, hasVerticalScroller=False) if f is not None: self.w.fontNameText.enable(False) self.w.inputText = GlyphSequenceEditText((x, row1+30, 200, 22), f.naked(), callback = self.inputTextCallback) self.w.ascenderText.enable(False) self.w.descenderText.enable(False) self.w.saveButton = SquareButton((x, 370, 200, 50), "Save PDF!", callback = self.saveButtonCallback) else: self.w.fontRef.enable(False) self.w.inputText = EditText((x, 40, 200, 22), "No open font") self.w.inputText.enable(False) self.w.grayLettersCheckbox.enable(False)
def get_ui(window_controller, title): glyph_column_descriptions = [ { "title": "Layers", "cell": vanilla.CheckBoxListCell(), "width": 35, "editable": False, }, { "title": "Name", "typingSensitive": True, "editable": False, }, ] layer_column_descriptions = [ { "title": "Index", "key": "layer_index", "width": 45, "editable": True, }, { "title": "ColorIndex", "key": "layer_color_index", "width": 45, "editable": True, }, # { # "title": "Color", # "binding": "selectedValue", # "cell": vanilla.PopUpButtonListCell([]), # "width": 30, # "editable": True, # }, { "title": "Layer Glyph", "typingSensitive": True, "editable": True, }, ] palette_column_descriptions = [ { "title": "Index", # "cell": IntType, #TODO "width": 60, "typingSensitive": True, }, { "title": "Color", "cell": RFColorCell.alloc().initWithDoubleClickCallback_( window_controller.paletteEditColorCell), "typingSensitive": False, "editable": False, }, ] layer_drop_settings = { "type": NSColorPboardType, "allowDropBetweenRows": False, "allowDropOnRow": True, "callback": window_controller._callback_layer_drop, } col2 = int(round(window_width / 2)) y = 10 w = vanilla.Window((window_width, 496), "%s - RoboChrome" % title) w.preview = Canvas( (10, y, 320, 200), canvasSize=(318, 200), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=window_controller, ) w.paletteswitch = vanilla.PopUpButton( (340, y, -10, 20), [], callback=window_controller._paletteSwitchCallback, ) w.colorpalette = vanilla.List( (340, y + 30, -10, 170), [], columnDescriptions=palette_column_descriptions, drawFocusRing=True, editCallback=window_controller.paletteEdit, selectionCallback=window_controller._callback_color_select_in_palette, allowsMultipleSelection=False, enableDelete=True, ) w.addPalette = vanilla.GradientButton( (340, 215, 24, 24), imagePath="../resources/iconColorFontPalette.pdf", callback=window_controller.paletteDuplicate, ) w.deletePalette = vanilla.GradientButton( (363, 215, 24, 24), imagePath="../resources/iconColorFontPaletteMinus.pdf", callback=window_controller.paletteDelete, ) w.addColorToPalette = vanilla.GradientButton( (410, 215, 24, 24), imagePath="../resources/iconColorFontPlus.pdf", callback=window_controller.addColorToPalette, ) y += 210 w.glyph_list_label = vanilla.TextBox((10, y, 120, 20), "Glyphs with layers:", sizeStyle="small") w.glyph_list_search_box = vanilla.SearchBox( (118, y - 3, 114, 20), placeholder="Filter glyphs", callback=window_controller._callback_update_ui_glyph_list, sizeStyle="small", ) w.colorChooser = vanilla.ColorWell( (240, y - 4, 40, 22), callback=window_controller._callback_color_changed_foreground, color=window_controller.color, ) w.colorbgChooser = vanilla.ColorWell( (290, y - 4, 40, 22), color=window_controller.colorbg, callback=window_controller._callback_color_changed_background) w.colorPaletteColorChooser = vanilla.ColorWell( (450, y - 4, 40, 22), callback=window_controller._callback_color_changed_layer, color=window_controller.color, ) y += 25 w.glyph_list = vanilla.List( (10, y, col2 - 10, 150), [], columnDescriptions=glyph_column_descriptions, drawFocusRing=True, #editCallback=None, doubleClickCallback=window_controller._callback_goto_glyph, selectionCallback=window_controller._callback_ui_glyph_list_selection, allowsMultipleSelection=False, ) w.layer_list = vanilla.List( (col2 + 10, y, -10, 150), [], columnDescriptions=layer_column_descriptions, drawFocusRing=True, editCallback=window_controller._callback_layer_edit, enableDelete=True, selectionCallback=window_controller._callback_layer_select, allowsMultipleSelection=False, otherApplicationDropSettings=layer_drop_settings, ) y += 160 w.show_only_glyphs_with_layers = vanilla.CheckBox( (10, y, 176, 20), "Show only glyphs with layers", callback=window_controller._callback_set_show_only_glyphs_with_layers, value=window_controller.show_only_glyphs_with_layers, sizeStyle="small") w.add_layer_button = vanilla.GradientButton( (col2 + 10, y - 10, 24, 24), imagePath="../resources/iconColorFontPlus.pdf", callback=window_controller._callback_layer_add, ) # w.add_svg_button = vanilla.Button( # (col2+43, y-10, 60, 24), # "Add SVG", # callback=window_controller._choose_svg_to_import, # sizeStyle="small" # ) y += 28 w.selectButton = vanilla.Button( (10, y, col2 - 10, 20), "Select glyphs with layers", callback=window_controller._callback_select_glyphs_in_font_window, ) w.auto_palette_button = vanilla.Button( (col2 + 10, y, 110, 20), "Mix palette", callback=window_controller._callback_auto_palette, ) w.png_button = vanilla.Button( (380, y, 110, 20), "Export PNG", callback=window_controller._choose_png_to_export, ) y += 31 w.toggleSettingsButton = vanilla.Button( (10, y, 115, 20), "Settings...", callback=window_controller._callback_toggle_settings, ) w.auto_layer_button = vanilla.Button( (135, y, 115, 20), "Auto layers", callback=window_controller._callback_auto_layers, ) w.import_button = vanilla.Button( (col2 + 10, y, 110, 20), "Import font", callback=window_controller._choose_file_to_import, ) w.export_button = vanilla.Button( (380, y, 110, 20), "Export to font", callback=window_controller._choose_file_to_export, ) return w
class TDGroupViewStacked(VanillaBaseObject): nsViewClass = NSView def __init__(self, posSize, selectionCallback=None, doubleClickCallback=None, sizeStyle='regular', liveupdate=False): xw, yw, tx, ty = posSize self.glyphsToDisplay = [] self.font = None self.hashKernDic = None self.direction = 'L' self.showSelected = False self.groupIsEmpty = False self.diffMarginsInGroup = False self.groupname = None self.keyGlyph = None self.keyGlyphMargin = None self.showMask = True self.showInfo = True self.imnotready = True self.liveupdate = liveupdate self.vertShift = 50 self._alpha = .1 self._scalefactorUI = .045 # sizeStyle = 'regular' ty = 85 if sizeStyle == 'big': self._scalefactorUI = .065 ty = 100 self.vertShift = 0 elif sizeStyle == 'small': self._scalefactorUI = .035 ty = 65 elif sizeStyle == 'mini': self._scalefactorUI = .025 ty = 45 elif sizeStyle == 'micro': self._scalefactorUI = .015 ty = 30 self.heightOfControl = ty self._selectionCallback = selectionCallback self._doubleClickCallbak = doubleClickCallback self.darkmode = KERNTOOL_UI_DARKMODE self.darkmodeWarm = KERNTOOL_UI_DARKMODE_WARMBACKGROUND self._selfHeight = ty self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.infoLine = Canvas( (0, 0, -0, -0), delegate=self, # canvasSize = (ty, ty), hasHorizontalScroller=False, hasVerticalScroller=False, autohidesScrollers=True, # backgroundColor = NSColor.whiteColor(), # acceptMouseMoved = True ) self.infoLine.scrollView.getNSScrollView().setBorderType_(NSNoBorder) self.infoLine.update() def setFont(self, font): self.font = font # self.glyphsToDisplay = [] # self.infoLine.update() def selected(self, selected=False): self.showSelected = selected self.infoLine.update() def setKeyGlyph(self, groupname): if len(self.font.groups[groupname]) > 0: gname = self.font.groups[groupname][0] self.keyGlyph = gname self.keyGlyphMargin = getKeyGlyphMargin(self.font, keyglyph=gname, direction=self.direction) self.groupIsEmpty = False else: self.keyGlyph = None self.keyGlyphMargin = 0 self.groupIsEmpty = True def setGroupStack(self, name, direction=None): # if self.groupname == name and not self.liveupdate: return if not direction: direction = getDirection(name) self.direction = direction self.glyphsToDisplay = [] self.diffMarginsInGroup = False if ID_KERNING_GROUP in name: self.groupname = name self.setKeyGlyph(groupname=self.groupname) if not self.keyGlyph: self.imnotready = False self.infoLine.update() return totalglyphs = len(self.font.groups[self.groupname]) if totalglyphs in range(0, 6): self._alpha = .3 else: self._alpha = .1 # self._alpha = (100/totalglyphs)/100 * len(self.font.groups[groupname]) for idx, glyphname in enumerate(self.font.groups[self.groupname]): if glyphname in self.font: self.glyphsToDisplay.append(self.font[glyphname]) if self.keyGlyphMargin != getKeyGlyphMargin( self.font, keyglyph=glyphname, direction=direction): self.diffMarginsInGroup = True else: if name in self.font: self.keyGlyph = name self.keyGlyphMargin = getKeyGlyphMargin( self.font, keyglyph=name, direction=self.direction) self.glyphsToDisplay.append(self.font[name]) self.groupname = name self.diffMarginsInGroup = False self.imnotready = False self.infoLine.update() def setupGroupViewExternal(self, groupname, glyphs, keyglyphname, margin, diffmargin, direction): # if self.groupname == groupname and not self.liveupdate: return self.groupname = groupname self.glyphsToDisplay = glyphs self.keyGlyph = keyglyphname self.keyGlyphMargin = margin self.diffMarginsInGroup = diffmargin self.direction = direction totalglyphs = len(glyphs) if totalglyphs in range(0, 6): self._alpha = .3 else: self._alpha = .1 self.imnotready = False self.infoLine.update() def mouseDown(self, event): if event.clickCount() == 2: if self._doubleClickCallbak: self._doubleClickCallbak(self.groupname) elif event.clickCount() == 1: if self._selectionCallback: self._selectionCallback(self.groupname) def draw(self): if self.imnotready: return stroke(0, 0, 0, 0) strokeWidth(0) font('Menlo', fontSize=10) visibleHeight = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.height visibleWidth = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.width # self.infoLine._view.setFrame_(NSMakeRect(0, 0, visibleWidth, visibleHeight)) def italicShift(angle, Ypos): if angle: italics_shift = Ypos * math.tan(abs(angle) * 0.0175) return italics_shift else: return 0 if self.darkmodeWarm: fillRGB((.75, .73, .7, .8)) # print('maxY', maxY) # if _rw < visibleWidth: # _rw = visibleWidth # + 500 rect(0, 0, visibleWidth, visibleHeight) scalefactor = self._scalefactorUI Xcenter = visibleWidth / 2 if self.font: if self.groupIsEmpty: #not self.glyphsToDisplay: fillRGB(COLOR_KERN_VALUE_NEGATIVE) if self.showSelected: fill(.1, 0, 1, 1) rect(0, 0, visibleWidth, 15) fill(1) text(getDisplayNameGroup(self.groupname), (5, 1)) return else: if self.keyGlyph: keyGlyph = self.font[ self.keyGlyph] # self.glyphsToDisplay[-1] keyWidth = keyGlyph.width else: keyWidth = 0 Xright = 0 Xleft = Xcenter - keyWidth / 2 Xright = Xleft + keyWidth font('Menlo', fontSize=9) if self.direction == 'L': if self.showMask: fill(.4) if self.font.info.italicAngle != 0: a = self.font.info.italicAngle h = visibleHeight w = visibleWidth polygon((0, 0), (0, h), (w / 2 + italicShift(a, h) / 2, h), (w / 2 - italicShift(a, h) / 2, 0)) else: rect(0, 0, (visibleWidth / 2), visibleHeight) fill(0, 0, 0, 1) shiftx = -6 xpos = visibleWidth - 16 # shiftx = shiftx * len(str(self.keyGlyphMargin)) shiftx, _y = textSize(str(self.keyGlyphMargin)) fill(0) text(str(self.keyGlyphMargin), (xpos - shiftx, visibleHeight - 17)) if self.diffMarginsInGroup: fillRGB(COLOR_KERN_VALUE_NEGATIVE) oval(visibleWidth - 13, visibleHeight - 14, 8, 8) elif self.direction == 'R': if self.showMask: fill(.4) if self.font.info.italicAngle != 0: a = self.font.info.italicAngle h = visibleHeight w = visibleWidth polygon((w / 2 - italicShift(a, h) / 2, 0), (w / 2 + italicShift(a, h) / 2, h), (w, h), (w, 0)) else: rect((visibleWidth / 2), 0, visibleWidth / 2, visibleHeight) fill(0) text(str(self.keyGlyphMargin), (17, visibleHeight - 17)) if self.diffMarginsInGroup: fillRGB(COLOR_KERN_VALUE_NEGATIVE) oval(5, visibleHeight - 14, 8, 8) # font('Menlo', fontSize = 10) fill(0) if self.showSelected: fill(.1, 0, 1, 1) # fill() # print NSColor.selectedMenuItemTextColor() rect(0, 0, visibleWidth, 15) txt = getDisplayNameGroup(self.groupname) txtshift = 2 font('Menlo', fontSize=10) if txt.startswith('@.'): txt = txt.replace('@.', '') txtshift = 10 fillRGB((1, .6, .2, 1)) text('@', 3, 2) fill(1) nx, ny = textSize(txt) if nx > visibleWidth - 15: font('Menlo', fontSize=8) text(txt, (3 + txtshift, 3)) else: text(txt, (3 + txtshift, 1)) translate(visibleWidth / 2 - visibleWidth / 40, (visibleHeight / 3)) # -4 stroke(0, 0, 0, 0) strokeWidth(0) scale(scalefactor) for idx, glyph in enumerate(self.glyphsToDisplay): save() pen = CocoaPen(self.font) if self.direction == 'L': translate(Xright - glyph.width, self.vertShift) elif self.direction == 'R': translate(Xleft, self.vertShift) fill(0, 0, 0, self._alpha) if glyph.name == self.keyGlyph: fill(0, 0, 0, 1) glyph.draw(pen) drawPath(pen.path) restore() translate(0, 0)
def __init__(self, posSize, separatePairs=True, selectionCallback=None, selectionPairCallback=None, selectionGlyphCallback=None, sizeStyle='regular', hasHorizontalScroller=True, showValues=False, showMargins=False, showNames=False): xw, yw, tx, ty = posSize # ty = 120 # self._posSize = (xw, yw, tx, 106) self.glyphsToDisplay = [] self.pairsToDisplay = None self.pairsViews = [] self._currentPairToDisplay = () self._font = None self._viewArray = [] self._selectedGlyph = None self._idxSelectedGlyph = 0 self._letterStep = 7 self._hasHorizontalScroller = hasHorizontalScroller self.hashKernDic = None self.separatorPairsWidth = 250 self.separatePairs = separatePairs self.toucheMode = False self.touchFlag = False self.lightmode = False self.valuesMode = showValues self.showMargins = showMargins self.showNames = showNames self.maxX = 0 self._mouseOver = False self.darkmode = KERNTOOL_UI_DARKMODE self.darkmodeWarm = KERNTOOL_UI_DARKMODE_WARMBACKGROUND self._scalefactorUI = .045 # sizeStyle = 'regular' ty = 85 if sizeStyle == 'extrabig': self._scalefactorUI = .090 ty = 180 if sizeStyle == 'big': self._scalefactorUI = .055 ty = 110 elif sizeStyle == 'small': self._scalefactorUI = .035 ty = 65 self.valuesMode = False self.showMargins = False self.showNames = False elif sizeStyle == 'mini': self._scalefactorUI = .027 ty = 50 self.valuesMode = False self.showMargins = False self.showNames = False elif sizeStyle == 'micro': self._scalefactorUI = .021 ty = 40 self.valuesMode = False self.showMargins = False self.showNames = False self.heightOfControl = ty self._selectedPair = None self._selectionCallback = selectionCallback self._selectionPairCallback = selectionPairCallback self._selectionGlyphCallback = selectionGlyphCallback self._selfHeight = ty self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.infoLine = Canvas( (0, 0, -0, -0), delegate=self, # canvasSize = (100, 101), hasHorizontalScroller=hasHorizontalScroller, hasVerticalScroller=False, autohidesScrollers=True, # backgroundColor = NSColor.whiteColor() ) self.infoLine.scrollView.getNSScrollView().setBorderType_(NSNoBorder)
class TDGroupLine(VanillaBaseObject): nsViewClass = NSView def __init__(self, posSize, separatePairs=True, selectionCallback=None, selectionPairCallback=None, selectionGlyphCallback=None, sizeStyle='regular', hasHorizontalScroller=True, showValues=False, showMargins=False, showNames=False): xw, yw, tx, ty = posSize # ty = 120 # self._posSize = (xw, yw, tx, 106) self.glyphsToDisplay = [] self.pairsToDisplay = None self.pairsViews = [] self._currentPairToDisplay = () self._font = None self._viewArray = [] self._selectedGlyph = None self._idxSelectedGlyph = 0 self._letterStep = 7 self._hasHorizontalScroller = hasHorizontalScroller self.hashKernDic = None self.separatorPairsWidth = 250 self.separatePairs = separatePairs self.toucheMode = False self.touchFlag = False self.lightmode = False self.valuesMode = showValues self.showMargins = showMargins self.showNames = showNames self.maxX = 0 self._mouseOver = False self.darkmode = KERNTOOL_UI_DARKMODE self.darkmodeWarm = KERNTOOL_UI_DARKMODE_WARMBACKGROUND self._scalefactorUI = .045 # sizeStyle = 'regular' ty = 85 if sizeStyle == 'extrabig': self._scalefactorUI = .090 ty = 180 if sizeStyle == 'big': self._scalefactorUI = .055 ty = 110 elif sizeStyle == 'small': self._scalefactorUI = .035 ty = 65 self.valuesMode = False self.showMargins = False self.showNames = False elif sizeStyle == 'mini': self._scalefactorUI = .027 ty = 50 self.valuesMode = False self.showMargins = False self.showNames = False elif sizeStyle == 'micro': self._scalefactorUI = .021 ty = 40 self.valuesMode = False self.showMargins = False self.showNames = False self.heightOfControl = ty self._selectedPair = None self._selectionCallback = selectionCallback self._selectionPairCallback = selectionPairCallback self._selectionGlyphCallback = selectionGlyphCallback self._selfHeight = ty self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.infoLine = Canvas( (0, 0, -0, -0), delegate=self, # canvasSize = (100, 101), hasHorizontalScroller=hasHorizontalScroller, hasVerticalScroller=False, autohidesScrollers=True, # backgroundColor = NSColor.whiteColor() ) self.infoLine.scrollView.getNSScrollView().setBorderType_(NSNoBorder) # self.infoLine.update() def setFont(self, font, hashKernDic): self._font = font self.hashKernDic = hashKernDic self.setPairsToDisplay([], []) # self.glyphsToDisplay = [] # self.pairsToDisplay = None # self.pairsViews = [] # # self._currentPairToDisplay = () # # self._viewArray = [] # # self._selectedGlyph = None # # self._idxSelectedGlyph = 0 # self.compilePairs() # # self.infoLine.update() def setPairsToDisplay(self, glyphsListUUID, pairList): # print 'got list:' if self.glyphsToDisplay != glyphsListUUID: self.resetPosition() self.glyphsToDisplay = glyphsListUUID self.pairsToDisplay = pairList self.compilePairs() self.infoLine.update() def setPair(self, pair, direction=None, deltaKern=None): if not direction: return l, r = pair pair = researchPair(self._font, self.hashKernDic, (l, r)) gL = pair['L_nameForKern'] gR = pair['R_nameForKern'] ggL = [] ggR = [] if direction == 'L': if self.hashKernDic.thisGroupIsMMK(gL): try: for ggname in self._font.groups[gL]: ggL.append(self._font[ggname].name) ggL.append(self._font[cutUniqName(r)].name) except: pass self.setPairsToDisplay( ggL, getListOfPairsToDisplay(self._font, self.hashKernDic, ggL, deltaKern=deltaKern)) elif direction == 'R': if self.hashKernDic.thisGroupIsMMK(gR): try: for ggname in self._font.groups[gR]: ggR.append(self._font[cutUniqName(l)].name) ggR.append(self._font[ggname].name) except: pass self.setPairsToDisplay( ggR, getListOfPairsToDisplay(self._font, self.hashKernDic, ggR, deltaKern=deltaKern)) elif direction == 'B': self.setPairsToDisplay([l, r], getListOfPairsToDisplay_previewDeltaKern( self._font, self.hashKernDic, [l, r], deltaKern=deltaKern, mixPairs=False)) return if not self.hashKernDic.thisGroupIsMMK( gL) and not self.hashKernDic.thisGroupIsMMK(gR): self.setPairsToDisplay([gL, gR], getListOfPairsToDisplay( self._font, self.hashKernDic, [gL, gR], deltaKern=deltaKern)) def setGlyphsLine(self, glyphslist): if glyphslist: self.setPairsToDisplay( glyphslist, getListOfPairsToDisplay(self._font, self.hashKernDic, glyphslist)) def get(self): return self.glyphsToDisplay def mouseDown(self, event): offset = self.separatorPairsWidth * self._scalefactorUI X_window_pos = event.locationInWindow().x X_local_pos = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().origin.x x = X_window_pos + X_local_pos # - self._letterStep selectedpair = () item = None for idx, item in enumerate(self._viewArray): # if idx+1 < len(self._viewArray): x0 = item['x0'] + offset # x1 = self._viewArray[idx+1]['x1'] x1 = item['x0'] + item['width'] * self._scalefactorUI - item[ 'kernValue'] * self._scalefactorUI + offset #+ self._viewArray[idx+1]['width']* self._scalefactorUI + offset if (x0 < x) and (x < x1): self._selectedGlyph = item self._idxSelectedGlyph = idx # print ('item', item) # print ('idx',idx) for pitem in self.pairsViews: pl, pr = pitem if pl == self._viewArray[ idx - 1]['nameUUID'] and pr == item['nameUUID']: selectedpair = (cutUniqName( self._viewArray[idx - 1]['nameUUID']), cutUniqName(item['nameUUID'])) # self._idxSelectedGlyph = idx if pl == item['nameUUID'] and pr == self._viewArray[ idx + 1]['nameUUID']: selectedpair = (cutUniqName(item['nameUUID']), cutUniqName( self._viewArray[idx + 1]['nameUUID'])) # self._idxSelectedGlyph = idx + 1 break if event.clickCount() == 2: if self._selectionCallback: self._selectionCallback(self.glyphsToDisplay) else: if decodeModifiers(event.modifierFlags()) == 'Alt': if self._selectionPairCallback and selectedpair: self._selectionPairCallback(selectedpair) else: if self._selectionGlyphCallback and item: # print (self._idxSelectedGlyph) self._selectionGlyphCallback( cutUniqName(self._viewArray[self._idxSelectedGlyph] ['nameUUID'])) self.infoLine.update() def resetView(self): self._viewArray = [] self.infoLine.update() def compilePairs(self): carretX = 0 x_1 = 0 self._viewArray = [] self.pairsViews = [] x_0 = 0 pcount = 0 lg = None rg = None for idx, glyphname in enumerate(self.glyphsToDisplay): # rulGlyph = [] kernValue = 0 if self.pairsToDisplay and (idx < len(self.pairsToDisplay)): pair = self.pairsToDisplay[idx] kernValue = pair['kernValue'] realname = cutUniqName(glyphname) glyph = self._font[realname] inGroup = False nameToDisplay = realname nameUUID = glyphname + '.' + getUniqName() if not kern(kernValue): kernValue = 0 carret = (kernValue + glyph.width) # * .2 x_1 = x_0 + carret self._viewArray.append({ 'x0': x_0 * self._scalefactorUI, 'x1': x_1 * self._scalefactorUI, 'name': nameToDisplay, # 'name': cutUniqName(glyphname), 'nameUUID': nameUUID, 'width': glyph.width, 'kernValue': kernValue, # 'leftMargin': s_Lm, # 'rightMargin': s_Rm, 'inGroup': inGroup }) x_0 = x_1 if self.separatePairs: pcount += 1 if pcount == 2: x_0 += self.separatorPairsWidth pcount = 0 self.pairsViews.append( (self._viewArray[idx - 1]['nameUUID'], nameUUID)) def resetPosition(self): point = NSPoint(0, 0) self.infoLine.scrollView.getNSScrollView().contentView( ).scrollToPoint_(point) self.infoLine.scrollView.getNSScrollView().reflectScrolledClipView_( self.infoLine.scrollView.getNSScrollView().contentView()) def scrollWheel(self, event): if not self._hasHorizontalScroller: return deltaX = event.deltaX() deltaY = 0 if deltaY == 0 and deltaX == 0: return scaleScroll = 5 visibleWidth = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.width - 20 visibleHeight = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.height posXscroller = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().origin.x posYscroller = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().origin.y xW, yW, wW, hW = self.getPosSize() xpoint = posXscroller - (deltaX * scaleScroll) if xpoint < xW: xpoint = 0 if xpoint > self.maxX - visibleWidth: xpoint = self.maxX - visibleWidth #+ 200 point = NSPoint(xpoint, posYscroller + (deltaY * scaleScroll)) self.infoLine.scrollView.getNSScrollView().contentView( ).scrollToPoint_(point) self.infoLine.scrollView.getNSScrollView().reflectScrolledClipView_( self.infoLine.scrollView.getNSScrollView().contentView()) def updatePanel(self): self.infoLine.update() def draw(self): self._viewFontName = 'Menlo' stroke(0, 0, 0, 0) strokeWidth(0) def drawSelectionCursor(x, y, color, markException=False): opt = 0 if markException: opt = 20 hw = 70 + opt x = x - hw fillRGB(color) newPath() moveTo((x, y)) lineTo((x + hw, y + hw + hw / 3 - opt)) lineTo((x + hw * 2, y)) closePath() drawPath() if markException: fill(1) if self.darkmodeWarm: fillRGB((.75, .73, .7, 1)) oh = 80 oval(x + (hw * 2 - oh) / 2, y - oh / 2 + 10, oh, oh) fillRGB(COLOR_KERN_VALUE_NEGATIVE) oh = 55 oval(x + (hw * 2 - oh) / 2, y - oh / 2 + 10, oh, oh) # self._viewFontSize = 6 #* self._scalefactorUI # font(self._viewFontName, fontSize = self._viewFontSize) visibleHeight = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.height ruller_compensation = self._selfHeight - visibleHeight X_local_pos = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().origin.x visibleHeight = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.height Y_local_pos = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().origin.y visibleWidth = self.infoLine.scrollView.getNSScrollView( ).documentVisibleRect().size.width Ypos = 0 # visibleHeight - 20 Ybase = Ypos maxX = 0 Xpos = 0 scalefactor = self._scalefactorUI shiftX = 200 maxX += shiftX # self.darkmode = True if self.darkmodeWarm: fillRGB((.75, .73, .7, .8)) _rw = self.maxX + 100 # print('maxY', maxY) if _rw < visibleWidth: _rw = visibleWidth #+ 500 rect(0, 0, _rw, visibleHeight) fillRGB(COLOR_BLACK) translate(shiftX * scalefactor, (visibleHeight / 3)) # * 2 ) save() stroke(0, 0, 0, 0) strokeWidth(0) scale(scalefactor) pcount = 0 # showSeparator = True widthSeparator = self.separatorPairsWidth paircount = len(self._viewArray) for idx, item in enumerate(self._viewArray): fillRGB(COLOR_BLACK) if self.toucheMode and not self.lightmode: if self.touchFlag: fillRGB(COLOR_TOUCHE) self.touchFlag = False if idx + 1 < len(self._viewArray): # if item['y0'] == self._viewArray[idx + 1]['y0']: kernValue = item['kernValue'] if kernValue == None: kernValue = 0 currGlyph = self._font[item['name']] nextGlyph = self._font[self._viewArray[idx + 1]['name']] if checkOverlapingGlyphs(currGlyph, nextGlyph, kernValue): fillRGB(COLOR_TOUCHE) self.touchFlag = True save() # try: maxX = item['x1'] glyph = self._font[item['name']] Xpos = item['x0'] / scalefactor pen = CocoaPen(self._font) translate(Xpos, 0) glyph.draw(pen) drawPath(pen.path) # except: # pass # translate(0,0) # Xpos = item['kernValue'] + item['width'] if self.showMargins: translate(-Xpos, 0) self._viewFontSize = 80 font(self._viewFontName, fontSize=self._viewFontSize) HVcontrol = 60 Vcontrol = 80 HVkern = 60 Ycontrol = -400 xlM = Xpos # item['x0'] xrM = Xpos + item['width'] + scalefactor t1 = Ycontrol + 120 # + 1200 t2 = HVcontrol wbar = 150 lbar = 5 gapbar = 30 glyph = self._font[item['name']] if self._font.info.italicAngle == 0 or not self._font.info.italicAngle: lM = int(round(glyph.leftMargin, 0)) rM = int(round(glyph.rightMargin, 0)) else: lM = int(round(glyph.angledLeftMargin, 0)) rM = int(round(glyph.angledRightMargin, 0)) fill(.5) if self.darkmodeWarm: fill(.3, .3, .3, 1) # leftMargin mark rect(xlM, t1, lbar, t2) # vbar rect(xlM, t1 + t2 - lbar, wbar, lbar) # hbar text(str(lM), (xlM + 30, t1 - 40)) # rightMargin mark rect(xrM - wbar, t1 + t2 - lbar + gapbar, wbar, lbar) # hbar rect(xrM - lbar, t1 + t2 - lbar + gapbar, lbar, t2 + lbar) # vbar rm = str(rM) # rmoff = len(rm)*40 + 45 nx, ny = textSize(rm) text(rm, (xrM - nx - 30, t1 + gapbar + 60)) self.showSelected = True if self.showSelected and idx == self._idxSelectedGlyph: # fillRGB(COLOR_L_GROUP_ICON) drawSelectionCursor( xlM + item['width'] / 2, Ycontrol - 180, COLOR_L_GROUP_ICON ) #+ item['width'] / 2 - lbar / 2 - wbar / 2 else: rect(xlM + item['width'] / 2 - lbar / 2, Ycontrol - 180 + lbar, lbar, t2) # vbar # if (item['lineNumberOfPairs'] != self._selectedLine): rect(xlM + item['width'] / 2 - lbar / 2 - wbar / 2, Ycontrol - 180, wbar, lbar) # hbar if self.showNames: gn = item['name'] nx, ny = textSize(gn) if nx > item['width']: l = len(gn) // 2 a1 = ''.join(gn[:l]) + '-' nx, ny = textSize(a1) b1 = ''.join(gn[l:]) text(a1, (xlM + item['width'] / 2 - nx / 2, Ycontrol + 1600)) text(b1, (xlM + item['width'] / 2 - nx / 2, Ycontrol + 1520)) else: text(gn, (xlM + item['width'] / 2 - nx / 2, Ycontrol + 1520)) rect(xlM + item['width'] / 2 - lbar / 2, Ycontrol + 1500 - HVcontrol, lbar, t2) # vbar # if (item['lineNumberOfPairs'] != self._selectedLine): rect(xlM + item['width'] / 2 - lbar / 2 - wbar / 2, Ycontrol + 1500, wbar, lbar) # hbar restore() restore() pcount = 0 self._viewFontSize = 80 * scalefactor font(self._viewFontName, fontSize=self._viewFontSize) translate(0, -1 * (visibleHeight / 9) * 2) if self.pairsToDisplay: # print self._pairsToDisplay for idx, pair in enumerate(self.pairsToDisplay): if idx < len(self._viewArray): item = self._viewArray[idx] x1L = item['x1'] HVcontrol = 60 * scalefactor Vcontrol = 80 HVkern = 60 * scalefactor Ycontrol = 0 if item['kernValue'] != None and not pair[ 'exception'] and pcount != 1: kV = item['kernValue'] if kV in range(1, 60): kV = 60 if kV in range(-60, 0): kV = -60 xK = item['x0'] + item['width'] * scalefactor if kV > 0: xK = item['x0'] + item[ 'width'] * scalefactor # + (shiftX * scalefactor) fillRGB(COLOR_KERN_VALUE_POSITIVE) rect(xK, Ycontrol + HVcontrol, abs(kV) * scalefactor, HVkern) if self.valuesMode: text(str(item['kernValue']), (xK + abs(kV) * scalefactor + 3, Ycontrol - HVcontrol)) # if item['exception']: # drawException(xK + abs(kV) / 2 - HVcontrol, Ycontrol - HVcontrol) # rect(xK, Ycontrol + HVcontrol, HVkern, HVkern) elif kV < 0: # xK = item['width'] xK = item[ 'x1'] # - HVkern/2# * scalefactor# + (shiftX * scalefactor) fillRGB(COLOR_KERN_VALUE_NEGATIVE) rect(xK, Ycontrol + HVcontrol, abs(kV) * scalefactor, HVkern) if self.valuesMode: text(str(item['kernValue']), (xK + abs(kV) * scalefactor + 3, Ycontrol - HVcontrol)) if pair['exception'] and pcount != 1: kV = item['kernValue'] if kV > 0: xK = item['x0'] + ( item['width'] * scalefactor) - 4 # + (shiftX * scalefactor) fillRGB(COLOR_KERN_VALUE_POSITIVE) if self.valuesMode: text(str(kV), (xK + abs(kV) * scalefactor + 5, Ycontrol - HVcontrol)) else: # kV < 0: xK = item['x1'] - 4 # + (shiftX * scalefactor) fillRGB(COLOR_KERN_VALUE_NEGATIVE) if self.valuesMode: text(str(kV), (xK + abs(kV) * scalefactor + 5, Ycontrol - HVcontrol)) x = xK y = 0 s = 1.1 newPath() moveTo((x + s * 4, y + s * 8)) lineTo((x + s * 1, y + s * 3)) lineTo((x + s * 4, y + s * 3)) lineTo((x + s * 4, y + s * 0)) lineTo((x + s * 7, y + s * 5)) lineTo((x + s * 4, y + s * 5)) closePath() drawPath() if self.separatePairs: pcount += 1 if pcount == 2: # translate(widthSeparator * scalefactor, 0) pcount = 0 # if self.separatePairs: # maxX += (widthSeparator*(paircount-2))* scalefactor if maxX < visibleWidth: maxX = visibleWidth self.infoLine._view.setFrame_( NSMakeRect(0, 0, maxX + 40, visibleHeight)) self.maxX = maxX
def __init__(self, interface): self.ui = interface self.windowWidth, self.windowHeight = 800, 600 self.w = Window((self.windowWidth, self.windowHeight), "Text Center", minSize=(200, 200)) self.inverse = 0 self.scale = .15 self.margin = 50 self.scroll = 0 self.scrollX = 0 self.scrollWheel_ZoomSensibility = .005 self.keyDown_ZoomSensibility = .05 self.glyphName2Glyph = {} self.selectedGlyph = None self.text = [] self.glyphLocation_in_Window = {} self.mainInputString = "" self.w.mainInputText_EditText = EditText( (100, 10, -100, 20), self.mainInputString, sizeStyle="small", callback=self._mainInputText_EditText_callback) self.leftInputString = "" self.w.leftInputText_EditText = EditText( (10, 10, 80, 20), self.leftInputString, sizeStyle="small", callback=self._leftInputText_EditText_callback) self.rightInputString = "" self.w.rightInputText_EditText = EditText( (-90, 10, -10, 20), self.rightInputString, sizeStyle="small", callback=self._rightInputText_EditText_callback) self.verticalMode = 0 self.w.verticalMode_checkBox = CheckBox( (10, -20, 150, -0), "Vertical Mode", value=self.verticalMode, sizeStyle="small", callback=self._verticalMode_checkBox_callback) self.lineHeight = 1000 self.w.lineHeight_Slider = Slider( (-220, -20, -120, -0), minValue=1000, maxValue=2000, value=self.lineHeight, callback=self._lineHeight_Slider_callback, sizeStyle="small") self.displayDesignFrame = 0 self.w.displayDesignFrame_checkBox = CheckBox( (-110, -20, -10, -0), "Design Frame", value=self.displayDesignFrame, sizeStyle="small", callback=self._displayDesignFrame_checkBox_callback) self.w.canvas = Canvas((0, 60, -0, -20), delegate=self, canvasSize=(10000, 10000)) Helpers.setDarkMode(self.w, self.ui.darkMode) self.w.bind('resize', self.windowDidResize) self.w.open()
def __init__(self, fonts): self.fonts = fonts if len(self.fonts) in range(4): self.min_unit_width = 350 self.p_point_size = 160 elif len(self.fonts) in range(4, 7): self.min_unit_width = 200 self.p_point_size = 120 else: self.min_unit_width = 150 self.p_point_size = 100 # by default, all checkboxes are unchecked self.checked = [0 for i in range(len(self.fonts))] self.min_w_width = len(self.fonts) * self.min_unit_width # cmb_kern_dict is an ordered dict self.cmb_kern_dict = kerningHelper.get_combined_kern_dict(fonts) self.pair_list = list(self.cmb_kern_dict.keys()) self.filtered_pairlists = self.make_filtered_pairlists( self.cmb_kern_dict) # initial value for the first pair to show initial_pair = self.pair_list[0] self.pair = initial_pair initial_value = self.cmb_kern_dict[initial_pair] self.values = initial_value self.steps = len(self.values) self.update_display(self.values) self.drag_index = None self.w = vanilla.Window( (self.min_w_width, self.min_w_height), title='Kern-A-Lytics', minSize=(self.min_w_width / 2, self.min_w_height / 2), ) _, _, self.w_width, self.w_height = self.w.getPosSize() self.graph_height = self.w_height / 3 self.graph_width = (self.w_width - 2 * self.padding) self.step_dist = self.graph_width / self.steps graph_margin = self.step_dist / 2 self.canvas_delegate = CanvasDelegate(self) self.w.c = Canvas( (self.padding, self.padding, -self.padding, self.graph_height), delegate=self.canvas_delegate, canvasSize=(self.graph_width, self.graph_height), # backgroundColor=AppKit.NSColor.orangeColor(), backgroundColor=AppKit.NSColor.clearColor(), drawsBackground=False, ) # buttons buttons = [ # button label, callback name ('Delete Pairs', 'delete_button_callback'), ('Average Pairs', 'average_button_callback'), ('Equalize Pairs', 'transfer_button_callback'), ('Interpolate Pair', 'interpolate_button_callback'), # ('Transfer Pair', 'transfer_button_callback'), ('+10', 'plus_button_callback'), ('-10', 'minus_button_callback'), ('+10%', 'dummy_button_callback'), ('-10%', 'dummy_button_callback'), ] button_top = -210 # list starts at 210 and has 10 padding at bottom # total whitespace: 200 height - 8 * 20 = 40 # individual_whitespace = 40 / (len(buttons) - 1) button_height = 20 button_space = len(buttons) * button_height button_whitespace = (abs(button_top) - self.padding) - button_space button_step_space = button_whitespace / (len(buttons) - 1) for i, (b_label, b_callback_name) in enumerate(buttons): button = vanilla.Button( (self.w_width - self.padding - self.button_width, button_top + i * button_height, self.button_width, button_height), b_label, callback=getattr(self, b_callback_name)) setattr(self.w, 'button_{}'.format(i), button) # button_top += self.padding / 2 button_top += button_step_space # graph labels with monospaced digits nsfont = AppKit.NSFont.monospacedDigitSystemFontOfSize_weight_(14, 0.0) for i, number in enumerate(self.label_values): tb_x = self.padding + graph_margin + i * self.step_dist self.tb_y = self.padding * 2 + self.graph_height self.tb_height = 20 self.tb_width = 100 tb_control = vanilla.TextBox( (tb_x - self.tb_width / 2, self.tb_y, self.tb_width, self.tb_height), number, alignment='center', sizeStyle='small', selectable=True, ) tb_control.getNSTextField().setFont_(nsfont) setattr(self.w, 'textbox_{}'.format(i), tb_control) # pair preview pp_origin_x = self.padding pp_origin_y = self.padding * 4 + self.graph_height + self.tb_height self.w.pairPreview = vanilla.Group( (pp_origin_x, pp_origin_y, self.w_width, self.p_point_size)) for f_index, f in enumerate(self.fonts): x = self.step_dist * f_index pair_preview = DrawPair((x, 0, self.step_dist, -0)) initial_pair = self.pair_list[0] kern_value = self.cmb_kern_dict.get(initial_pair)[f_index] if kern_value is None: kern_value = 0 repr_pair = kerningHelper.get_repr_pair(f, initial_pair) # XXXX the following line is problematic # if UFOs with different group structures are opened repr_glyphs = [f[g_name] for g_name in repr_pair] pair_preview.setGlyphData_kerning(repr_glyphs, kern_value) setattr(self.w.pairPreview, 'pair_{}'.format(f_index), pair_preview) # checkboxes for i, f in enumerate(self.fonts): cb_x = self.padding + graph_margin + i * self.step_dist cb_control = vanilla.CheckBox( (cb_x - 6, pp_origin_y + self.p_point_size + self.padding * 2, 22, 22), '', value=False, sizeStyle='regular', callback=self.checkbox_callback) setattr(self.w, 'checkbox_{}'.format(i), cb_control) # pop-up button for list filtering list_width = self.w_width - self.button_width - self.padding * 3 self.w.list_filter = vanilla.PopUpButton((10, -240, list_width, 20), self.filter_options, callback=self.filter_callback) # list of kerning pairs (bottom) column_pairs = self.make_columns(self.pair_list) self.w.display_list = vanilla.List( (10, -210, list_width, -10), column_pairs, columnDescriptions=[{ 'title': 'L' }, { 'title': 'R' }], allowsMultipleSelection=False, selectionCallback=self.list_callback) self.w.bind('resize', self.resize_callback) self.w.open()
class GlyphLayers(Group): def __init__(self, posSize, interface): super(GlyphLayers, self).__init__(posSize) self.ui = interface self.storageGlyph = None self.storageGlyphName = "" self.StorageGlyphCurrentLayer = "" self.jumpTo = SearchBox((0,0,165,20), placeholder = "Char/Name", sizeStyle = "small", callback = self._jumpTo_callback ) self.displayGlyphset_settingList = ['find Char/Name', "Sort by key"] self.displaySettings = 'find Char/Name' self.displayGlyphset_setting = PopUpButton((170, 0, 200, 20), self.displayGlyphset_settingList, sizeStyle = "small", callback = self._displayGlyphset_setting_callback) self.glyphset = [] self.glyphset_List = List((0,20,165,-200), self.glyphset, columnDescriptions = [ {"title": "Char", "width" : 30}, {"title": "Name", "width" : 105}, ], drawFocusRing=False, selectionCallback = self._glyphset_List_selectionCallback, ) self.set_glyphset_List() self.layersCanvas = Canvas((165,20,-0,-200), delegate=LayersCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False) slider = SliderListCell(minValue = 0, maxValue = 1000) self.slidersValuesList = [] self.sliderList = List((0,-190,350,-0),self.slidersValuesList, columnDescriptions = [{"title": "Layer" }, {"title": "Values", "cell": slider}], editCallback = self._sliderList_editCallback, drawFocusRing = False, allowsMultipleSelection = False) self.layersPreviewCanvas = Canvas((350,-190,-0,-0), delegate=LayersPreviewCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False) def getGlyphset(self): return [dict(Char=chr(int(name.split("_")[0],16)), Name = name) for name in self.ui.font2Storage[self.ui.font].keys()] def _displayGlyphset_setting_callback(self, sender): self.displaySettings = self.displayGlyphset_settingList[sender.get()] if self.displaySettings == 'find Char/Name': self.ui.glyphset = self.ui.font.lib['public.glyphOrder'] # glyphset = [dict(Char=chr(int(name.split("_")[0],16)), Name = name) for name in self.ui.font2Storage[self.ui.font].keys()] self.glyphset = self.getGlyphset() self.glyphset_List.set(self.glyphset) def set_glyphset_List(self): if self.ui.font in self.ui.glyphsSetDict and self.displaySettings == 'find Char/Name': self.glyphset = self.getGlyphset() self.glyphset_List.set(self.glyphset) def _glyphset_List_selectionCallback(self, sender): sel = sender.getSelection() if not sel: return self.storageFont = self.ui.font2Storage[self.ui.font] self.storageGlyphName = sender.get()[sel[0]]["Name"] self.storageGlyph = self.ui.font2Storage[self.ui.font][self.storageGlyphName] self.setSliderList() self.layersCanvas.update() self.layersPreviewCanvas.update() def setSliderList(self): self.slidersValuesList = [dict(Layer=layerName, Values=0) for layerName in self.storageGlyph.lib['deepComponentsLayer'] if layerName != "foreground"] self.sliderList.set(self.slidersValuesList) def _sliderList_editCallback(self, sender): self.slidersValuesList = sender.get() self.layersPreviewCanvas.update() def _jumpTo_callback(self, sender): string = sender.get() if not string: self.glyphset_List.setSelection([]) self.glyphset_List.set(self.glyphset) self.ui.glyphset = self.ui.font.lib['public.glyphOrder'] return try: if self.displaySettings == 'find Char/Name': glyphSet = [e["Name"].split('_')[0] for e in self.glyphset] if string.startswith("uni"): index = glyphSet.index(string[3:]) elif len(string) == 1: code = "uni"+normalizeUnicode(hex(ord(string[3:]))[2:].upper()) index = glyphSet.index(code) else: index = glyphSet.index(string) self.glyphset_List.setSelection([index]) elif self.displaySettings == 'Sort by key': glyphSet = [e["Name"] for e in self.glyphset] name = string if string.startswith("uni"): name = string[3:] elif len(string) == 1: name = normalizeUnicode(hex(ord(string))[2:].upper()) self.glyphset_List.set([dict(Name = names, Char = chr(int(names.split('_')[0],16))) for names in glyphSet if name in names]) except: pass
class GlyphSet(Group): def __init__(self, posSize, interface): super(GlyphSet, self).__init__(posSize) self.ui = interface self.jumpTo = SearchBox( (0, 0, 165, 20), placeholder="Char/Name", sizeStyle="small", callback=self._jumpTo_callback, # continuous = False, ) self.glyphset_List = List( (0, 20, 165, -0), [], columnDescriptions=[ { "title": "Char", "width": 30 }, { "title": "Name", "width": 105 }, ], drawFocusRing=False, selectionCallback=self._glyphset_List_selectionCallback, doubleClickCallback=self._glyphset_List_doubleClickCallback) self.displayGlyphset_settingList = ['find Char/Name', "Sort by key"] self.displaySettings = 'find Char/Name' self.displayGlyphset_setting = PopUpButton( (170, 0, 200, 20), self.displayGlyphset_settingList, sizeStyle="small", callback=self._displayGlyphset_setting_callback) self.set_glyphset_List() self.canvas = Canvas((165, 20, -0, -0), delegate=CurrentGlyphCanvas(self.ui, self), hasHorizontalScroller=False, hasVerticalScroller=False) def _displayGlyphset_setting_callback(self, sender): self.displaySettings = self.displayGlyphset_settingList[sender.get()] if self.displaySettings == 'find Char/Name': self.ui.glyphset = self.ui.font.lib['public.glyphOrder'] glyphset = self.ui.glyphsSetDict[self.ui.font] self.glyphset_List.set(glyphset) def set_glyphset_List(self): if self.ui.font in self.ui.glyphsSetDict: glyphset = self.ui.glyphsSetDict[self.ui.font] self.glyphset_List.set(glyphset) def _glyphset_List_selectionCallback(self, sender): sel = sender.getSelection() if not sel: return if self.ui.glyphset: name = self.ui.glyphset[sel[0]] self.ui.glyph = self.ui.font[name] self.ui.getCompositionGlyph() self.ui.selectedVariantName = "" self.ui.currentGlyph_DeepComponents = { 'CurrentDeepComponents': {}, 'Existing': {}, 'NewDeepComponents': {}, } self.ui.getDeepComponents_FromCurrentGlyph() self.ui.w.activeMasterGroup.glyphData.glyphCompositionRules_List.setSelection( []) self.ui.w.activeMasterGroup.glyphData.glyphCompositionRules_List.set( self.ui.compositionGlyph) self.ui.w.activeMasterGroup.glyphData.variants_List.set([]) self.ui.w.activeMasterGroup.DeepComponentsInstantiator.setSliderList() self.ui.w.activeMasterGroup.DeepComponentsInstantiator.newDeepCompo.list.set( []) self.ui.w.activeMasterGroup.DeepComponentsInstantiator.deepCompo_segmentedButton.set( 0) self.ui.w.activeMasterGroup.DeepComponentsInstantiator.newDeepCompo.show( 0) self.ui.w.activeMasterGroup.DeepComponentsInstantiator.selectDeepCompo.show( 1) self.ui.newDeepComponent_active = False self.canvas.update() def _glyphset_List_doubleClickCallback(self, sender): sel = sender.getSelection() if not sel: return if self.ui.glyph is None: return OpenGlyphWindow(self.ui.glyph) gw = CurrentGlyphWindow() appearance = NSAppearance.appearanceNamed_( 'NSAppearanceNameVibrantDark') gw.window().getNSWindow().setAppearance_(appearance) def _jumpTo_callback(self, sender): string = sender.get() if not string: glyphset = self.ui.glyphsSetDict[self.ui.font] self.glyphset_List.setSelection([]) self.glyphset_List.set(glyphset) self.ui.glyphset = self.ui.font.lib['public.glyphOrder'] return try: if self.displaySettings == 'find Char/Name': # self.ui.glyphset = self.ui.glyphsSetDict[self.ui.font] if string.startswith("uni"): index = self.ui.glyphset.index(string) elif len(string) == 1: code = "uni" + normalizeUnicode( hex(ord(string))[2:].upper()) index = self.ui.glyphset.index(code) self.glyphset_List.setSelection([index]) elif self.displaySettings == 'Sort by key': name = string if string.startswith("uni"): name = string[3:] elif len(string) == 1: name = normalizeUnicode(hex(ord(string))[2:].upper()) self.ui.glyphset = self.ui.key2Glyph[name] self.glyphset_List.set([ dict(Name=name, Char=chr(int(name[3:], 16)) if name.startswith('uni') else "") for name in self.ui.glyphset ]) except: pass
class TDExceptionLine(VanillaBaseObject): nsViewClass = NSView def __init__ (self, posSize, selectionCallback=None, sizeStyle='big'): xw, yw, tx, ty = posSize self.glyphsToDisplay = [] self.keyGlyph = None self.font = None self.hashKernDic = None self.direction = 'L' self.showSelected = False self.groupIsEmpty = False self.diffMarginsInGroup = False self.groupname = None self.keyGlyph = None self.keyGlyphMargin = None self.showInfo = True self.excGlyphL = None self.excGlyphR = None self.kernValue = 0 self.darkmode = KERNTOOL_UI_DARKMODE self.darkmodeWarm = KERNTOOL_UI_DARKMODE_WARMBACKGROUND self._alpha = .1 self._scalefactorUI = .045 # sizeStyle = 'regular' ty = 85 if sizeStyle == 'big': self._scalefactorUI = .065 ty = 100 elif sizeStyle == 'small': self._scalefactorUI = .035 ty = 65 elif sizeStyle == 'mini': self._scalefactorUI = .025 ty = 45 elif sizeStyle == 'micro': self._scalefactorUI = .015 ty = 30 self.heightOfControl = ty self._selectionCallback = selectionCallback self._selfHeight = ty self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.infoLine = Canvas((0, 0, -0, -0), delegate = self, # canvasSize = (ty, ty), hasHorizontalScroller = False, hasVerticalScroller = False, autohidesScrollers = True, backgroundColor = NSColor.whiteColor(), # acceptMouseMoved = True ) self.infoLine.scrollView.getNSScrollView().setBorderType_(NSNoBorder) # self.infoLine.update() def setFont (self, font, hashKernDic): self.font = font self.hashKernDic = hashKernDic def selected (self, selected=False): self.showSelected = selected self.infoLine.update() # if self._selectionCallback and selected: # self._selectionCallback(self) def setKeyGlyph (self, groupname): if len(self.font.groups[groupname]) > 0: gname = self.font.groups[groupname][0] self.keyGlyph = gname else: self.keyGlyph = None self.keyGlyphMargin = 0 self.groupIsEmpty = True def setupGroupView (self, groupname): self.glyphsToDisplay = [] self.diffMarginsInGroup = False self.groupname = groupname self.setKeyGlyph(groupname = groupname) if not self.keyGlyph: return totalglyphs = len(self.font.groups[groupname]) if totalglyphs in range(0, 6): self._alpha = .3 else: self._alpha = .1 for idx, glyphname in enumerate(self.font.groups[groupname]): if glyphname in self.font: self.glyphsToDisplay.append(self.font[glyphname]) self.infoLine.update() def setPair (self, pair, direction): self.direction = direction l, r = pair pair = researchPair(self.font, self.hashKernDic, (l, r)) self.excPairName = (l, r) gL = pair['L_nameForKern'] gR = pair['R_nameForKern'] if not pair['kernValue']: self.kernValue = 0 else: self.kernValue = pair['kernValue'] if self.direction == 'L': self.resultPair = (gL, r) self.setupGroupView(gL) elif self.direction == 'R': self.resultPair = (l, gR) self.setupGroupView(gR) elif self.direction == 'B': self.resultPair = (l, r) self.infoLine.update() def mouseDown (self, event): if self._selectionCallback: self._selectionCallback(self) def resetView (self): self.infoLine.update() def draw (self): def drawLeftCursor (txt, Xcenter, Ycontrol, color): m = 17 y = Ycontrol fsize = 10 step = 0 # 6.55 font('Menlo', fsize * m) fill(0, 0, 0, 1) txlen, _y = textSize(txt) if color: fillRGB(COLOR_EXCEPTION_GROUP_ICON) # w = step * len(txt) * m + step * m w = txlen + 140 Xpos = Xcenter - w + 20 newPath() moveTo((Xpos, y)) curveTo((Xpos - 7 * m, y), (Xpos - 7 * m, y + 2 * m), (Xpos - 7 * m, y + 7 * m)) curveTo((Xpos - 7 * m, y + 12 * m), (Xpos - 7 * m, y + 14 * m), (Xpos, y + 14 * m)) # lineTo((Xpos + w, y + 14 * m)) lineTo((Xpos + w, y + 14 * m)) lineTo((Xpos + w - 3 * m, y + 7 * m)) lineTo((Xpos + w, y + 7 * m)) lineTo((Xpos + w - 3 * m, y)) lineTo((Xpos + w, y)) closePath() drawPath() fill(1, 1, 1, 1) text(txt, (Xpos, y + 1.5 * m)) def drawRightCursor (txt, Xcenter, Ycontrol, color): m = 17 y = Ycontrol fsize = 10 step = 0 #6.55 font('Menlo', fsize * m) fill(0, 0, 0, 1) txlen, _y = textSize(txt) if color: fillRGB(COLOR_EXCEPTION_GROUP_ICON) # w2 = step * len(txt) * m + (step / 2) * m + step * m w2 = txlen + 140 Xpos = Xcenter - 20 w = 0 newPath() moveTo((Xpos + w, y)) # lineTo((Xpos + w, y + 14 * m)) lineTo((Xpos + 3 * m, y + 7 * m)) lineTo((Xpos, y + 7 * m)) lineTo((Xpos + 3 * m, y + 14 * m)) lineTo((Xpos + w + w2, y + 14 * m)) curveTo((Xpos + w + w2 + 7 * m, y + 14 * m), (Xpos + w + w2 + 7 * m, y + 12 * m), (Xpos + w + w2 + 7 * m, y + 7 * m)) curveTo((Xpos + w + w2 + 7 * m, y + 2 * m), (Xpos + w + w2 + 7 * m, y), (Xpos + w + w2, y)) closePath() drawPath() fill(1, 1, 1, 1) text(txt, (Xpos + w + step * m + 140, y + 1.5 * m)) visibleHeight = self.infoLine.scrollView.getNSScrollView().documentVisibleRect().size.height visibleWidth = self.infoLine.scrollView.getNSScrollView().documentVisibleRect().size.width scalefactor = self._scalefactorUI Xcenter = visibleWidth / 2 # if not self.glyphsToDisplay: return if self.keyGlyph: keyGlyph = self.font[self.keyGlyph] # self.glyphsToDisplay[-1] keyWidth = keyGlyph.width else: keyWidth = 0 Xright = 0 Xleft = Xcenter # - keyWidth/2 Xright = Xleft # + keyWidth if self.darkmodeWarm: fillRGB((.75, .73, .7, .8)) # _rw = self.maxX+100 # # print('maxY', maxY) # if _rw < visibleWidth: # _rw = visibleWidth #+ 500 rect(0, 0, visibleWidth, visibleHeight) translate(visibleWidth / 2 - visibleWidth / 30, (visibleHeight / 3)) # -4 stroke(0, 0, 0, 0) strokeWidth(0) scale(scalefactor) if self.direction != 'B': for idx, glyph in enumerate(self.glyphsToDisplay): save() pen = CocoaPen(self.font) if self.direction == 'L': translate(Xcenter - glyph.width, 0) elif self.direction == 'R': translate(self.kernValue + Xcenter, 0) fill(0, 0, 0, self._alpha) if glyph.name == self.keyGlyph: fill(0, 0, 0, 1) glyph.draw(pen) drawPath(pen.path) restore() translate(0, 0) save() (l, r) = self.resultPair pen = CocoaPen(self.font) if self.direction == 'L': glyph = self.font[r] translate(self.kernValue + Xcenter, 0) elif self.direction == 'R': glyph = self.font[l] translate(Xcenter - glyph.width, 0) fillRGB(COLOR_EXCEPTION_GROUP_ICON) glyph.draw(pen) drawPath(pen.path) restore() translate(0, 0) elif self.direction == 'B': save() (l, r) = self.resultPair pen = CocoaPen(self.font) glyph = self.font[l] translate(Xcenter - glyph.width, 0) fillRGB(COLOR_EXCEPTION_GROUP_ICON) glyph.draw(pen) drawPath(pen.path) restore() translate(0, 0) save() pen = CocoaPen(self.font) glyph = self.font[r] translate(self.kernValue + Xcenter, 0) fillRGB(COLOR_EXCEPTION_GROUP_ICON) glyph.draw(pen) drawPath(pen.path) restore() translate(0, 0) if self.showSelected: Ycontrol = -450 (l, r) = self.resultPair if self.direction == 'L': drawLeftCursor(getDisplayNameGroup(l),Xcenter-20, Ycontrol,False) drawRightCursor(r, Xcenter+20,Ycontrol,True) elif self.direction == 'R': drawLeftCursor(l, Xcenter-20, Ycontrol, True) drawRightCursor(getDisplayNameGroup(r), Xcenter+20, Ycontrol, False) elif self.direction == 'B': drawLeftCursor(l, Xcenter-20, Ycontrol, True) drawRightCursor(r, Xcenter+20, Ycontrol, True) self.infoLine._view.setFrame_(NSMakeRect(0, 0, visibleWidth, visibleHeight))
def __init__(self): self.histogram_width = 608 self.histogram_height = 380 histogram_x_offset = 10 histogram_y_offset = 10 window_width = 630 window_height = 500 # how much of the em is shown? self.ems_horizontal = 1.3 # how many pixels on the canvas per letter? self.scale_vertical = 10.0 self.units = 18 self.known_units = unitization_info.get_all_units() self.system = None self.show_fixed = True self.glyphs = [] # show glyphs or lines? self.show_glyphs = True y = 10 self.w = vanilla.FloatingWindow((window_width, window_height), "Glyph Width Histogram") self.w.histogram = Canvas((histogram_x_offset, histogram_y_offset, -10, self.histogram_height), canvasSize=(self.histogram_width, self.histogram_height), hasHorizontalScroller=False, hasVerticalScroller=False, delegate=self) y += self.histogram_height + histogram_y_offset + 8 self.w.unit_label = vanilla.TextBox((histogram_x_offset, y, 90, 20), "Units per em:") self.w.unit_display = vanilla.TextBox((histogram_x_offset + 90, y, 30, 20), self.units) self.w.system_selection = vanilla.PopUpButton((histogram_x_offset + 120, y-1, 300, 20), [], callback = self._systemCallback, #sizeStyle = "small", ) self.w.show_fixed = vanilla.CheckBox((histogram_x_offset + 462, y-1, 300, 20), "Show system widths", value=self.show_fixed, callback = self._showFixedCallback, ) y += 28 self.w.unit_slider = vanilla.Slider((histogram_x_offset, y, -10, 20), minValue = 1, maxValue = 64, value = self.units, tickMarkCount = 64, callback = self._unitCallback, stopOnTickMarks = True, ) y += 33 self.w.glyph_selection_label = vanilla.TextBox((histogram_x_offset, y, 120, 20), "Analyze glyphs:") self.w.glyph_selection = vanilla.RadioGroup((histogram_x_offset + 110, y, 210, 20), ["Selected", "All", "Charset:"], isVertical = False, callback = self._glyphSelectionCallback, sizeStyle = "small", ) self.w.charset_selection = vanilla.PopUpButton((histogram_x_offset + 320, y, -110, 20), [], callback = self._charsetCallback, #sizeStyle = "small", ) self.w.update_button = vanilla.Button((-100, y, -10, 20), "Update", callback = self._updateButtonCallback ) self._unitCallback() self.w.system_selection.setItems(unitization_info.get_ui_list()) if self.units in self.known_units: self.system = unitization_info.get_systems_by_upm(self.units)[0] self.w.system_selection.set(unitization_info.get_ui_list().index(self.system.name)) else: self.system = None self.w.system_selection.set(0) self.w.glyph_selection.set(0) self.w.charset_selection.enable(False) self.update_charset_selection() self.glyphs = self.get_glyphnames_for_histogram() self.calculate_histogram() self.setUpBaseWindowBehavior() #addObserver(self, "glyphChanged", "currentGlyphChanged") #addObserver(self, "glyphChanged", "draw") #addObserver(self, "removeFontFromList", "fontWillClose") #addObserver(self, "updateFontList", "fontDidOpen") self.w.open()
class TDMenuAdvanced(VanillaBaseObject): nsViewClass = NSView def __init__(self, posSize, selectionCallback=None, window=None): xw, yw, tx, ty = posSize self._window = window self._linesToDisplay = [] # self._font = None self._fontMenu = [] self._viewArray = [] self._selectedLine = 0 self._positionYselected = 0 self._lineSize = 1800 # 1800 # 1800=1000upm; 2400=2000upm self.Ygap = 0 # - yw*2 self.shiftX = 150 self._scalefactorUI = .03 self.scaleStep = 1.2 self.lineCount = 0 self.maxX = 0 self.maxXX = 0 self._lastGlyphXpos = 0 self._selectionCallback = selectionCallback self.showselection = False self._setupView(self.nsViewClass, (xw, yw, tx, ty)) # (0, 0, -0, 106) self.canvas = Canvas( (0, 0, -0, -0), delegate=self, # canvasSize = (100, 101), hasHorizontalScroller=False, hasVerticalScroller=True, autohidesScrollers=False, backgroundColor=NSColor.whiteColor(), drawsBackground=True, # acceptsMouseMoved = True ) self.canvas.scrollView.getNSScrollView().setBorderType_(NSNoBorder) fonts = AllFonts() for font in fonts: if font.info.familyName and font.info.styleName: # print font.info.familyName # print font.info.styleName self.addMenuItem(font=font, title=font.info.familyName + ' ' + font.info.styleName) self.compileLines() # print self.w.menu._viewArray self.canvas.update() self.scrollToLine(0) # self.canvas.update() def addMenuItem(self, font, title): tline = [] for glyphName in tdGlyphparser.translateText(font, title): tline.append('%s.%s' % (glyphName, getUniqName())) if tline: self._linesToDisplay.append({'font': font, 'title': tline}) def menuSelectedCallback(self): if self._selectionCallback: self._selectionCallback( self._linesToDisplay[self._selectedLine]['font']) self._window.close() def scrollToLine(self, linenumber): if not self._viewArray: return visibleWidth = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.width visibleHeight = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.height posXscroller = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.x posYscroller = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.y scale = self._scalefactorUI xpos = 0 ypos = 0 firstItemInLine = 0 for idx, item in enumerate(self._viewArray): if item['lineNumberOfPairs'] == linenumber: self._positionYselected = item['y0'] self._selectedLine = item['lineNumberOfPairs'] self._selectedBlock = item['blockNumberOfPairs'] firstItemInLine = idx # self.fillHashOfLine(idx, self._selectedLine) # self.fillHashOfBlock(0,self._selectedBlock) break maxY = self._viewArray[-1]['y0'] y0 = (maxY + (-1 * self._positionYselected)) * scale y1 = y0 + (self._lineSize * scale) if y0 < posYscroller: ypos = y0 elif y1 - posYscroller > visibleHeight: offset = visibleHeight - self._lineSize * scale ypos = y0 - offset # + posYscroller else: return firstItemInLine point = NSPoint(xpos, ypos) self.canvas.scrollView.getNSScrollView().contentView().scrollToPoint_( point) self.canvas.scrollView.getNSScrollView().reflectScrolledClipView_( self.canvas.scrollView.getNSScrollView().contentView()) return firstItemInLine # if not self._viewArray: return # visibleWidth = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.width # visibleHeight = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.height # posXscroller = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.x # posYscroller = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.y # scale = self._scalefactorUI # xpos = 0 # ypos = 0 # for idx, item in enumerate(self._viewArray): # if item['lineNumberOfPairs'] == linenumber: # self._positionYselected = item['y0'] # self._selectedLine = item['lineNumberOfPairs'] # self._selectedBlock = item['blockNumberOfPairs'] # break # # ypos = l['y0'] * scale # maxY = self._viewArray[-1]['y0'] # y0 = (maxY + (-1 * self._positionYselected)) * scale # y1 = y0 + (self._lineSize * scale) # # if y0 < posYscroller: # ypos = y0 # elif y1 - posYscroller > visibleHeight: # offset = visibleHeight - self._lineSize * scale # ypos = y0 - offset # + posYscroller # else: # return # # point = NSPoint(xpos, ypos) # self.canvas.scrollView.getNSScrollView().contentView().scrollToPoint_(point) # self.canvas.scrollView.getNSScrollView().reflectScrolledClipView_( # self.canvas.scrollView.getNSScrollView().contentView()) def scrollToBlock(self, linenumber): for item in self._viewArray: if item['blockNumberOfPairs'] == linenumber: # yPn = item['y0'] self.scrollToLine(item['lineNumberOfPairs']) break def getSelectedLine(self): result = [] for idx, item in enumerate(self._viewArray): if item['lineNumberOfPairs'] == self._selectedLine: result.append(item['name']) return '/' + '/'.join(result) def mouseDown(self, event): visibleHeight = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.height Y_local_pos = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.y X_window_pos = event.locationInWindow().x Y_window_pos = event.locationInWindow().y X_local_pos = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.x Y_local_pos = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.y xW, yW, x2W, y2W = self.getPosSize() # print xW, yW, x2W, y2W x = X_window_pos + X_local_pos # - self._letterStep y = Y_window_pos + y2W + Y_local_pos # print x, y self.showselection = True maxY = 0 if self._viewArray: maxY = self._viewArray[-1]['y0'] for idx, item in enumerate(self._viewArray): x0 = item['x0'] * self._scalefactorUI x1 = (item['x1'] + self.shiftX) * self._scalefactorUI # y0 = item['yV'] * self._scalefactorUI y0 = (maxY + (-1 * item['y0'])) * self._scalefactorUI # y1 = (y0 + self._lineSize) * self._scalefactorUI y1 = y0 + ((self._lineSize + self.Ygap) * self._scalefactorUI ) # - self.Ygap * self._scalefactorUI if (x0 < x and x < x1) and (y0 < y and y < y1): self._selectedLine = item['lineNumberOfPairs'] self.canvas.update() self.menuSelectedCallback() # self._selectionCallback(self._selectedLine) # if event.clickCount() == 2: # if decodeModifiers(event.modifierFlags()) == 'Alt': # self.postMessageToKernTool(message = 'full line') # # postEvent('typedev.KernTool.setGlyphsLine', glyphsLine = self.getSelectedBlock()) # else: # self.postMessageToKernTool(message = 'short line') # postEvent('typedev.KernTool.setGlyphsLine', glyphsLine = self.getSelectedLine()) # print item['blockNumberOfPairs'], item['lineNumberOfPairs'] , x0, x1, y0, y1 # self._packInfoForSelectionEvent() break def keyDown(self, event): # print event keypress = decodeCanvasKeys(event.keyCode(), event.modifierFlags()) commands = translateKeyCodesToKernToolCommands(keypress) # if commands['command'] == COMMAND_ZOOM_IN: # scale = self._scalefactorUI * self.scaleStep # if scale < .3: # self._scalefactorUI = scale # self.setSize(self._scalefactorUI) # # if commands['command'] == COMMAND_ZOOM_OUT: # scale = self._scalefactorUI / self.scaleStep # if scale > .045: # self._scalefactorUI = scale # self.setSize(self._scalefactorUI) if commands['command'] == COMMAND_ENTER: # print 'need refresh' self.showselection = True # self._selectionCallback(self._selectedLine) self.menuSelectedCallback() self.canvas.update() # self.s if commands['command'] == COMMAND_ESCAPE: self._selectedLine = None self._window.close() # self.menuSelectedCallback() # print 'need refresh' # self.showselection = True # # self._selectionCallback(self._selectedLine) # self.menuSelectedCallback() # self.canvas.update() if commands['command'] == COMMAND_NEXT_LINE_SHORT: n = self._selectedLine + 1 self.scrollToLine(n) self.canvas.update() if commands['command'] == COMMAND_PREV_LINE_SHORT: n = self._selectedLine - 1 self.scrollToLine(n) self.canvas.update() # if commands['command'] == COMMAND_NEXT_LINE: # n = self._selectedBlock + 1 # self.scrollToBlock(n) # self.canvas.update() # if commands['command'] == COMMAND_PREV_LINE: # n = self._selectedBlock - 1 # self.scrollToBlock(n) # self.canvas.update() # if commands['command'] == COMMAND_SWITCH_TOUCHE_MODE: # self.toucheMode = not self.toucheMode # print 'touche mode:', self.toucheMode # self.canvas.update() # if commands['command'] == COMMAND_SWITCH_VALUES_MODE: # self.valuesMode = not self.valuesMode # print 'values mode:', self.valuesMode # self.canvas.update() # if commands['command'] == COMMAND_OPEN_PAIRS_FILE: # print 'open file' # pairsfile = getFile(messageText = 'message', title = 'title') # self.loadText(filepath = pairsfile) # self.canvas.update() # if commands['command'] == COMMAND_OPEN_PAIRS_BUILDER: # # print 'Pairs Builder' # self._pairsBuilder() def mouseUp(self, event): # pass self.showselection = False self.canvas.update() def compileLines(self, mode='rebuild'): # mode = 'refresh' visibleWidth = 500 # self.visibleWidth self._viewArray = [] self.maxX = 0 # self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.width scale = self._scalefactorUI lineStep = self._lineSize shiftX = self.shiftX Xshift = 50 Xpos = shiftX Ypos = 0 carret = 0 smartmode = False self.lineCount = 0 virtShift = 0 widthvirt = 0 kernValuevirt = 0 idxLine = 0 maxY = 0 # if self._viewArray: # maxY = self._viewArray[-1]['y0'] scalefactor = self._scalefactorUI # visibleWidth = self.visibleWidth # visibleHeight = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.height # ruller_compensation = self._selfHeight - visibleHeight # Y_local_pos = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.y # X_local_pos = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.x # # # print Y_local_pos # Y_min_window = Y_local_pos # Y_max_window = Y_local_pos + visibleHeight # if mode == 'rebuild': for menuitem in self._linesToDisplay: font = menuitem['font'] title = menuitem['title'] # line = item['line'] # leftglyph = item['basic'] # idxLine = item['idxLine'] # YposV = item['Ypos'] # self._viewArray = [] # if not ((Y_min_window - self._lineSize * scalefactor <= ((maxY + (-1 * YposV)) * scalefactor) # and Y_max_window >= ((maxY + (-1 * YposV)) * scalefactor))): break hashKernDic = TDHashKernDic(font=font) self._pairsToDisplay = getListOfPairsToDisplay( font, hashKernDic, title) for idx, glyphnameUUID in enumerate(title): kernValue = 0 exception = False idxLine = idx if self._pairsToDisplay and (idx < len(self._pairsToDisplay)): pair = self._pairsToDisplay[idx] kernValue = pair['kernValue'] exception = pair['exception'] realname = cutUniqName(glyphnameUUID) glyph = font[realname] nameToDisplay = realname if not kernValue: kernValue = 0 width = glyph.width self._viewArray.append({ 'name': cutUniqName(glyphnameUUID), 'nameUUID': glyphnameUUID, 'width': width, 'font': font, 'kernValue': pair['kernValue'], 'exception': exception, 'x0': Xpos, 'x1': kernValue + Xpos + width, 'y0': Ypos, 'yV': Ypos, 'blockNumberOfPairs': idxLine, 'lineNumberOfPairs': self.lineCount, 'virtual': False }) Xpos += kernValue + width carret += kernValue + width carret = shiftX Ypos += lineStep Xpos = shiftX self.lineCount += 1 # item['Ypos'] = Ypos self.recalculateFrame(visibleWidth) def scrollWheel(self, event): scaleUI = self._scalefactorUI # deltaX = event.deltaX() deltaY = event.deltaY() # print deltaY # if deltaY in range(0,1500): return# and deltaX == 0: return if deltaY == 0: return # if deltaY > 0 and # time.sleep(.02) scaleScroll = 2 visibleWidth = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.width visibleHeight = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.height posXscroller = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.x posYscroller = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.y xW, yW, wW, hW = self.getPosSize() xpoint = 0 # xpoint = posXscroller - (deltaX * scaleScroll) ypoint = posYscroller + (deltaY * scaleScroll) # if xpoint > self.maxXX - visibleWidth: # - visibleWidth: # xpoint = self.maxXX - visibleWidth # - self.visibleWidth #- visibleWidth # if xpoint < xW: # xpoint = 0 # print deltaY, ypoint, posYscroller, visibleHeight if ypoint < 0: ypoint = 0 # return maxY = 0 if self._viewArray: maxY = self._viewArray[-1]['y0'] if posYscroller + visibleHeight - self._lineSize * scaleUI > maxY * scaleUI: ypoint = maxY * scaleUI - visibleHeight + self._lineSize * scaleUI #- deltaY # ypoint = posYscroller + visibleHeight - self._lineSize * scaleUI elif posYscroller + visibleHeight - self._lineSize * scaleUI == maxY * scaleUI and deltaY > 0: ypoint = maxY * scaleUI - visibleHeight + self._lineSize * scaleUI point = NSPoint(xpoint, ypoint) self.canvas.scrollView.getNSScrollView().contentView().scrollToPoint_( point) self.canvas.scrollView.getNSScrollView().reflectScrolledClipView_( self.canvas.scrollView.getNSScrollView().contentView()) # # if event.deltaY() > 0: # # self.stepToNextLine() # # elif event.deltaY() < 0: # # self.stepToPrevLine() # scaleUI = self._scalefactorUI # deltaX = event.deltaX() # deltaY = event.deltaY() # if deltaY == 0 and deltaX == 0 : return # # if deltaX > -10 and deltaX < 10 : deltaX = 0 # # print deltaX # # print self.visibleWidth # scaleScroll = 5 # visibleWidth = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.width # visibleHeight = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.height # posXscroller = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.x # posYscroller = self.canvas.scrollView.getNSScrollView().documentVisibleRect().origin.y # # # print visibleWidth, self.visibleWidth # # # if posYscroller < 0 : posYscroller = 0 # # if posXscroller < 0 : posXscroller = 0 # # if visibleWidth > self.visibleWidth : deltaX = 0 # # xW, yW, wW, hW = self.getPosSize() # xpoint = posXscroller - (deltaX * scaleScroll) # ypoint = posYscroller + (deltaY * scaleScroll) # if xpoint > self.maxXX - visibleWidth: # - visibleWidth: # xpoint = self.maxXX - visibleWidth #- self.visibleWidth #- visibleWidth # if xpoint < xW: # xpoint = 0 # # if ypoint < 0: ypoint = 0 # # maxY = self._viewArray[-1]['y0'] # # if posYscroller+visibleHeight-self._lineSize*scaleUI > maxY*scaleUI: # # ypoint = maxY*scaleUI - visibleHeight+self._lineSize*scaleUI # # # # point = NSPoint(xpoint, ypoint) # # self.canvas.scrollView.getNSScrollView().contentView().scrollToPoint_(point) # self.canvas.scrollView.getNSScrollView().reflectScrolledClipView_( # self.canvas.scrollView.getNSScrollView().contentView()) # # self.canvas.update() def recalculateFrame(self, canvaswidth=None): scalefactor = self._scalefactorUI if canvaswidth: visibleWidth = canvaswidth else: visibleWidth = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.width self.visibleWidth = visibleWidth visibleHeight = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.height yoff = (self.lineCount * self._lineSize) * scalefactor # + self.Ygap*2 if yoff < visibleHeight: yoff = visibleHeight #+ 500 self.canvas._view.setFrame_(NSMakeRect(0, 0, visibleWidth + 60, yoff)) self.maxXX = visibleWidth + 60 # scalefactor = self._scalefactorUI # # if canvaswidth: # visibleWidth = canvaswidth # else: # visibleWidth = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.width # # print visibleWidth, self.maxX # # if self.maxX > visibleWidth: # # visibleWidth = self.maxX # self.visibleWidth = visibleWidth # visibleHeight = self.canvas.scrollView.getNSScrollView().documentVisibleRect().size.height # yoff = ((self.lineCount) * self._lineSize) * scalefactor # if yoff < visibleHeight: # yoff = visibleHeight # self.canvas._view.setFrame_(NSMakeRect(0, 0, visibleWidth, yoff)) # self.maxXX = visibleWidth l, t, w, h = self._window.getPosSize() # # print l, t, w, h, ((self.lineCount+1) * self._lineSize) * scalefactor if self.lineCount < 5: self._window.resize( w, (((self.lineCount + 1) * self._lineSize) * scalefactor) - 20) def draw(self): self.recalculateFrame(self.visibleWidth) self._viewFontName = 'Menlo' self._viewFontSize = 80 font(self._viewFontName, fontSize=self._viewFontSize) visibleWidth = self.visibleWidth visibleHeight = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().size.height Y_local_pos = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.y X_local_pos = self.canvas.scrollView.getNSScrollView( ).documentVisibleRect().origin.x scalefactor = self._scalefactorUI shiftX = self.shiftX Ygap = self.Ygap scale(scalefactor) stroke(0, 0, 0, 0) strokeWidth(0) Ygap = 250 yoff = ((self.lineCount - 1) * self._lineSize) + Ygap # if (yoff * scalefactor) < visibleHeight: # yoff = (visibleHeight / scalefactor) - self._lineSize + Ygap # yoff = ((self.lineCount -1 ) * self._lineSize)# * scalefactor # if yoff < visibleHeight: # yoff = visibleHeight # yoff -= self._lineSize if self._viewArray: maxY = self._viewArray[-1]['y0'] # y0 = (maxY + (-1 * r['y0'])) * scale # flag = False save() translate(shiftX, yoff + Ygap) for idx, item in enumerate(self._viewArray): # print item Xpos = item['x0'] Ypos = item['y0'] if (item['lineNumberOfPairs'] == self._selectedLine): if self.showselection: fillRGB(COLOR_L_PAIR_SELECTION) else: fillRGB(COLOR_R_PAIR_SELECTION) rect(-1 * shiftX, -1 * Ypos - 490, 500 / scalefactor, self._lineSize) restore() # save() translate(shiftX, yoff + Ygap) for idx, item in enumerate(self._viewArray): Xpos = item['x0'] Ypos = item['y0'] save() if (item['lineNumberOfPairs'] == self._selectedLine): fillRGB(COLOR_WHITE) else: fillRGB(COLOR_BLACK) glyph = item['font'][item['name']] pen = CocoaPen(item['font']) translate(Xpos, -1 * Ypos) # item['yV'] = yoff - Ypos # - Ygap glyph.draw(pen) drawPath(pen.path) restore()