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)
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
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 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()
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 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))