コード例 #1
0
 def draw_background(self, notification):
     s  = notification['scale']
     g1 = notification['glyph']
     # get colors
     _mark_color = self.w.mark_color.get()
     _mark_color = (
         _mark_color.redComponent(),
         _mark_color.greenComponent(),
         _mark_color.blueComponent(),
         _mark_color.alphaComponent(),
     )
     _mark_color_2 = self.w.mark_color_2.get()
     _mark_color_2 = (
         _mark_color_2.redComponent(),
         _mark_color_2.greenComponent(),
         _mark_color_2.blueComponent(),
         _mark_color_2.alphaComponent(),
     )
     # get fonts
     f1 = CurrentFont()
     i  = self.w.f2.get()
     f2 = self.all_fonts[sorted(self.all_fonts.keys())[i]]
     r = 2
     # interpolate steps
     if f1 != f2:
         # check if f2 has this glyph
         if f2.has_key(g1.name):
             g2 = f2[g1.name]
             # check if glyph in f2 is compatible
             if g1.isCompatible(g2):
                 # create colors
                 c1 = Color.NewFromRgb(*_mark_color)
                 c2 = Color.NewFromRgb(*_mark_color_2)
                 colors = c1.Gradient(c2, self.steps)
                 # create steps and draw
                 for i in range(self.steps):
                     factor = i * (1.0 / (self.steps-1))
                     g3 = RGlyph()
                     g3.interpolate(factor, g1, g2)
                     save()
                     fill(None)
                     stroke(*colors[i])
                     strokeWidth(s)
                     if g3.width != g1.width:
                         diff = g3.width - g1.width
                         translate(-diff*0.5, 0)
                     drawGlyph(g3)
                     for c in g3.contours:
                         for pt in c.points:
                             rect(pt.x-r, pt.y-r, r*2, r*2)
                     restore()
                 # done
                 # restore()
         else:
             if self.verbose:
                 print '%s not in font 2' % g1.name
コード例 #2
0
 def applyCallback(self, sender):
     if self.currentGlyph is not None:
         xml = self.w.xml.get()
         
         dummyGlyph = RGlyph()
         try:
             readGlyphFromString(str(xml), dummyGlyph, dummyGlyph.getPointPen())
         except:
             import traceback
             error = "A problem occured when trying to parse the glif plist."
             suggestion = traceback.format_exc(5)
             self.showMessage(error, suggestion)
             return
             
         self.currentGlyph.clear()
         readGlyphFromString(str(xml), self.currentGlyph, self.currentGlyph.getPointPen())
コード例 #3
0
	def extraGlyphsCallback(self, *sender):
		del self.extraGlyphsList[:] # empty the list
		self.extraGlyphs = self.w.extraGlyphs.get()
		glyphNamesList = self.extraGlyphs.split()
		for gName in glyphNamesList:
			try:
				extraGlyph = self.font[gName]
				# must create a new glyph in order to be able to increase the sidebearings without modifying the font
				newGlyph = RGlyph()
				newGlyph.setParent(self.font)
				# must use deepAppend because the extra glyph may have components (which will cause problems to the MultiLineView)
				newGlyph = self.deepAppendGlyph(newGlyph, extraGlyph)
				newGlyph.width = extraGlyph.width
			except RoboFontError:
				continue
			newGlyph.leftMargin += self.extraSidebearings[0]
			newGlyph.rightMargin += self.extraSidebearings[1]
			self.extraGlyphsList.append(newGlyph)
		self.glyphPreviewCacheDict.clear()
		self.updateExtensionWindow()
コード例 #4
0
	def updateCalibrateMode(self, *sender):
		glyphsList = []
		newLine = self.w.lineView.createNewLineGlyph()

		# cycle thru the UI Groups and collect the strings
		for i in range(1,5):
			group = getattr(self.cm, "group%d" % i)
			baseGlyphsNamesList = group.baseInput.get().split()
			markGlyphsNamesList = group.markInput.get().split()

			# iterate thru the base+mark combinations
			for gBaseName, gMarkName in product(baseGlyphsNamesList, markGlyphsNamesList):
				newGlyph = RGlyph()
				newGlyph.setParent(self.font)
				# skip invalid glyph names
				try:
					baseGlyph = self.font[gBaseName]
					markGlyph = self.font[gMarkName]
				except RoboFontError:
					continue
				# append base glyph
				newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
				# append mark glyph
				newGlyph = self.deepAppendGlyph(newGlyph, markGlyph, self.getAnchorOffsets(baseGlyph, markGlyph))
				# set the advanced width
				dfltSidebearings = self.upm * .05 # 5% of the UPM
				newGlyph.leftMargin = dfltSidebearings + self.extraSidebearings[0]
				newGlyph.rightMargin = dfltSidebearings + self.extraSidebearings[1]
				# append the assembled glyph to the list
				glyphsList.extend(self.extraGlyphsList)
				glyphsList.append(newGlyph)

			# add line break, if both input fields have content
			if baseGlyphsNamesList and markGlyphsNamesList:
				glyphsList.extend(self.extraGlyphsList)
				glyphsList.append(newLine)

		# update the contents of the MultiLineView
		self.w.lineView.set(glyphsList)
コード例 #5
0
def RedArrowReportFactory(glyph, font):
    glyph = RGlyph(glyph)
    font = glyph.getParent()
    return getGlyphReport(font, glyph, options)
コード例 #6
0
	def updateExtensionWindow(self):
		if self.calibrateMode:
			self.updateCalibrateMode()
			return

		if CurrentGlyph() is not None: # NOTE: CurrentGlyph() will return zero (its length), so "is not None" is necessary
			self.glyph = CurrentGlyph()
			self.glyphNamesList = self.makeGlyphNamesList(self.glyph)
			self.updateListView()
			currentGlyphName = self.glyph.name

			# base glyph + accent combinations preview
			# first check if there's a cached glyph
			if currentGlyphName in self.glyphPreviewCacheDict:
				self.w.lineView.set(self.glyphPreviewCacheDict[currentGlyphName])

			# assemble the glyphs
			else:
				glyphsList = []
				for glyphNameInUIList in self.glyphNamesList:
					newGlyph = RGlyph()
					newGlyph.setParent(self.font)

					# the glyph in the UI list is a mark
					if glyphNameInUIList in self.marksDict:
						markGlyph = self.font[glyphNameInUIList]

						# append base glyph
						newGlyph = self.deepAppendGlyph(newGlyph, self.glyph)
						# append mark glyph
						newGlyph = self.deepAppendGlyph(newGlyph, markGlyph, self.getAnchorOffsets(self.glyph, markGlyph))

						# set the advanced width
						if self.glyph.width < 10: # combining marks or other glyphs with a small advanced width
							newGlyph.leftMargin = self.upm * .05 # 5% of the UPM
							newGlyph.rightMargin = newGlyph.leftMargin
						else:
							newGlyph.width = self.glyph.width

					# the glyph in the UI list is a base
					else:
						baseGlyph = self.font[glyphNameInUIList]

						# append base glyph
						newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
						# append mark glyph
						newGlyph = self.deepAppendGlyph(newGlyph, self.glyph, self.getAnchorOffsets(baseGlyph, self.glyph))

						# set the advanced width
						if self.glyph.width < 10: # combining marks or other glyphs with a small advanced width
							newGlyph.leftMargin = self.upm * .05
							newGlyph.rightMargin = newGlyph.leftMargin
						else:
							newGlyph.width = baseGlyph.width

					# pad the new glyph if it has too much overhang
					if newGlyph.leftMargin < self.upm * .15:
						newGlyph.leftMargin = self.upm * .05
					if newGlyph.rightMargin < self.upm * .15:
						newGlyph.rightMargin = self.upm * .05

					# add extra sidebearings
						newGlyph.leftMargin += self.extraSidebearings[0]
						newGlyph.rightMargin += self.extraSidebearings[1]

					# one last check for making sure the new glyph can be displayed
					if not newGlyph.components:
						glyphsList.extend(self.extraGlyphsList)
						glyphsList.append(newGlyph)
					else:
						print "Combination with mark glyph %s can't be previewed because it contains component %s." % (glyphNameInUIList, newGlyph.components[0].baseGlyph)

				glyphsList.extend(self.extraGlyphsList)
				self.w.lineView.set(glyphsList)

				# add to the cache
				self.glyphPreviewCacheDict[currentGlyphName] = glyphsList
		else:
			self.w.lineView.set([])