Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Solved
    • Unsolved
    • Search
    1. Home
    2. RicardGarcia
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by RicardGarcia

    • RE: RFont subclass not generating "otf"

      Hi, @frederik:

      why generate a binary and read the the binary back in? see f1.generate("otfcff", "f1.otf")

      You mean I can use the opened ufo files right away as f1 and f2 to interpolate with, right?

      Give you new font a unique name based on the interp_factor. The font familyName and styleName makes up the postScriptName which has to be unique to set a font in drawBot (and everywhere else). In your case the font familyName and styleName will be "None" "None". This is not good...

      All right. I thought that after uninstalling the interpolated font I could generate another one I could use in the new page afterwards. So, in this case, would it make sense to set the same name for familyName while the styleName could be related to inerp_factor as you say?

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: RFont subclass not generating "otf"

      Hi again. Even though both of your comments helped me a lot I'm still facing a last problem that I don't know how to solve.

      From my opened ufos, I'm generating a new interpolated font that I'm using in each frame to make an animation. The point is that, if I'm writting the factorright away like 0, .25or 1 it does the correct interpolation but it doesn't if I use the variable interp_factor. Is it something about overwritting the new_f.otf file?

      I've tried to clean the code as much as possible and hope that helps others pointing out what's going on here:

      text2Use  = """
      A monospaced font, also called a fixed-pitch, fixed-width, or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space.
      """
      
      def animationInstagram(text = text2Use):
          
          # Size of the page in px
          w, h = 1200, 2134.4
          
          # Number of frames
          frames = 4
              
          # Step factor
          maxFactor = 1
          stepFactor = maxFactor / (frames)
          
          # Interpolation factor (starting point)
          interp_factor = 1
          
      
          #Accessing opened ufos
          f1, f2 = AllFonts()[0], AllFonts()[1]
      
          f1.generate("otfcff", "f1.otf")
          f_1 = OpenFont("f1.otf", showInterface=False)
      
          f2.generate("otfcff", "f2.otf")  
          f_2 = OpenFont("f2.otf", showInterface=False)
          
          
          # Frames
          for f in range(frames):
              # Page settings
              newPage( w , h )
              
              fill(0) # BG
              rect(0,0,w,h)
              
              fill(1) # FG
      
              # Creating font to interpolate
              new_f = NewFont(showInterface=False)
              new_f.interpolate(interp_factor, f_1, f_2, round=False)
              print("Interpolation factor: ", interp_factor)
          
              new_f.generate("otfcff", "new_f.otf")
          
              #Installing the interpolated (temporary) font
              fontName = installFont("new_f.otf")
      
              # ------------------
              # Text box
              extraSpace = -200
      
              boxX, boxY, boxW, boxH = extraSpace, extraSpace, w-extraSpace*2.7, h-extraSpace*2
          
              font(fontName, 100)
              textBox(text, (boxX, boxY, boxW, boxH), align="left")
              
              # ------------------
      
              # Subtracting step factor
              interp_factor -= stepFactor
      
              # Uninstalling
              uninstallFont("new_f.otf")
      
      # Calling the function
      animationInstagram()
         
      # Saving the image
      saveImage("Test-interpolation.gif")
      
      

      Thank you so much once again!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: RFont subclass not generating "otf"

      Thank you so much for your help to both of you. @gferreira, the example you linked is super helpful and clear. I've read a bunch of code samples in Robofont's website and I don't know why I didn't run into this one. @frederik, thanks! I think that the main thing I was doing wrong was doing it outside Robofont. With the hints you both gave me I can manage to do what I wanted inside Robofont.

      Thanks!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: RFont subclass not generating "otf"

      I see. Then, if I want to make an animation with a long text interpolating between two .ufo files, which would be the the best option? Generating a .designspace with an axis, export the .otf and use it in the script?

      For what you say, it looks doable also inside Robofont itself, though.

      Thanks!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RFont subclass not generating "otf"

      Hello,

      I'm working on a set of animations that are going to use some .ufos I have and I'm facing a problem that I don't know how to solve. The point is that I want to generate otf files out of them while using generateto the Font object but it says The RFont subclass does not implement this method. Any idea what I'm doing wrong?

      Here's a simplyfied version of the code that returns this error:

      from fontParts.world import NewFont, OpenFont
      
      ufos = ['Patufet-Black.ufo', 'Patufet-Light.ufo']
      
      new_f = OpenFont(ufos[0], showInterface=False)
      print(new_f)
      new_f.generate("otfcff", "_Install-otf/new_f.otf")
      

      Thanks.

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Thanks Frederik! I think I've managed to have what I wanted to. Thanks a lot for bringing the whole problem to a more easy approach.

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Hi, Frederik. The point now is that it is using some functionalities I don't know how to translate into a more generic context using currentFont(), for instance. Now I'm using a function inside Glyph's API called completeBezierPathwhich draws what's inside a glyph cell. I've been making the script much simpler but still I have this small details. Is there something similar to this GLyphs function that I could use?

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Hi @frederik, I'm posting the script itself (even though it's a bit long) but before, maybe this will help knowing what's happening. So I'm doing an animation out of different frames and each frame has a glyph drawn in it. When I'm using Drawbot inside Glyphs its drawing both frame (red background) and the glyph in white.

      When it comes to run the script outside Drawbot (inside Glyphs), it keeps drawing the red background and each frame but it is no longer drawing the glyph. I guess it could have to do with completeBezierPathfrom Glyphs but I've used before and it works in other scripts.

      Here the script:

      # ---------------------
      # Modules
      # ---------------------
      from GlyphsApp import *
      from drawBot import *
      from AppKit import NSColor
      import vanilla, math
      import textwrap
      import os
      
      
      # ---------------------
      # Empty stack for Drawbot
      newDrawing()
      
      
      # ---------------------
      # Clear log in Macro Panel
      Glyphs.clearLog()
      
      
      
      class singleGlyphsAnimation( object ):
      	"""GUI generating an animation with all selected characters in the Font level"""
      
      	def __init__( self ):
      		
      		# Window sizes
      		windowW = 350
      		windowH = 320
      		
      		# UI elements
      		linePos = 20
      		margin = 20
      		lineHeight = 23
      		columnLine = 140
      		#print(columnLine)
      		
      
      
      		# Building window
      		self.w = vanilla.FloatingWindow(
      			 ( windowW, windowH ),
      			 "Animation generator"
      			 )
      
      		# ·····················································
      
      		# Title
      		self.w.descriptionText = vanilla.TextBox( (margin, linePos-5, -margin, lineHeight), "Select the characters you want in the animation", sizeStyle = "small")
      		# Opening the window
      		self.w.open()
      		
      		# ·····················································
      		
      		
      		
      		linePos += lineHeight*1.4
      		#self.w.line0 = HorizontalLine((margin, int(linePos+4), -margin, 1))
      		#linePos += lineHeight
      
      		
      		
      		# ·····················································
      		
      		# Page format (in pixels)
      		self.w.pageFormatTitle = vanilla.TextBox((margin, linePos, -margin, lineHeight), "Set frame format (px):", sizeStyle = "small")
      		
      		# ·····················································
      
      		# ColorWell
      		self.w.ColorWellTitle = vanilla.TextBox((columnLine + 40, linePos, 200, lineHeight), "Set colors:", sizeStyle = "small")
      
      		# ·····················································
      
      
      		linePos += lineHeight
      		# Width
      		self.w.widthTitle = vanilla.TextBox((margin*3, linePos+2, 100, lineHeight), "Width", sizeStyle = "small") 
      		self.w.widthUser = vanilla.EditText((110, linePos, 50, 20), "1920", sizeStyle = "small")
      		#print(int(str(self.w.widthUser.get())))
      		
      		
      		# Foreground color
      		self.w.fgColorTitle = vanilla.TextBox((columnLine + margin*3, linePos+2, 100, lineHeight), "Foreground", sizeStyle = "small") 
      		self.w.fgColorWell = vanilla.ColorWell((columnLine + 20 + 120, linePos, 50, 20), color = NSColor.colorWithCalibratedRed_green_blue_alpha_(255/255, 255/255, 255/255, 1))
      		#print(self.w.fgColorWell.get())
      		linePos += lineHeight
      		
      		# Height
      		self.w.heightTitle = vanilla.TextBox((margin*3, linePos+2, 100, lineHeight), "Height", sizeStyle = "small") 
      		self.w.heightUser = vanilla.EditText((110, linePos, 50, 20), "1200", sizeStyle = "small")
      		
      		# Background color
      		self.w.bgColorTitle = vanilla.TextBox((columnLine + margin*3, linePos+2, 100, lineHeight), "Background", sizeStyle = "small") 
      		self.w.bgColorWell = vanilla.ColorWell((columnLine + 20 + 120, linePos, 50, 20), color = NSColor.colorWithCalibratedRed_green_blue_alpha_(0/255, 0/255, 0/255, 1))
      		#print(self.w.bgColorWell.get())
      
      		
      		# ·····················································
      
      
      		linePos += lineHeight +3
      		self.w.line = vanilla.HorizontalLine((margin, int(linePos+12), columnLine, 1))
      		self.w.line2 = vanilla.HorizontalLine((columnLine + 40, int(linePos+12), -margin, 1))
      		linePos += lineHeight
      
      
      		# ·····················································
      
      		# Frame duration title
      		self.w.frameDurationTitle = vanilla.TextBox((margin, linePos+2, 200, lineHeight), "Set frame duration:", sizeStyle = "small") 
      		
      		# Enable show nodes
      		self.w.showNodes = vanilla.CheckBox((columnLine + 40, linePos-2, -margin, lineHeight), "Show nodes", value = False, sizeStyle = "small")
      		#print(self.w.showNodes.get())
      		
      		self.w.showNodes.getNSButton().setToolTip_("If enabled, it will show the nodes and handles instead of a filled version of the characters.")
      		
      		
      		
      		# Frame duration edit
      		linePos += lineHeight
      		self.w.frameTextEdit = vanilla.TextBox((margin*3, linePos+2, 100, lineHeight), "Fps", sizeStyle = "small") 
      		self.w.frameDurationUser = vanilla.EditText((110, linePos, 50, 20), "10", sizeStyle = "small")
      
      
      		# ·····················································
      
      
      		linePos += lineHeight
      		self.w.line3 = vanilla.HorizontalLine((margin, int(linePos+15), -margin, 1))
      		linePos += lineHeight
      
      
      		# ·····················································
      		
      		# Saving file format
      		self.w.savingFormatTitle = vanilla.TextBox((margin, int(linePos+10), columnLine, lineHeight), "Select the file format:", sizeStyle = "small")
      		
      		self.w.popUpFormat = vanilla.PopUpButton((columnLine+10, linePos+7, -margin, 20),
                                    [".gif", ".mov", ".jpg", ".pdf"])
      
      		
      		# ·····················································
      		
      		
      		linePos += lineHeight * 3
      		
      		
      		# ·····················································
      		# Generate button
      		
      		self.w.generateAnimation = vanilla.Button((margin, linePos, -margin, lineHeight), "Generate animation", sizeStyle = "small", callback = self.generateAnimation)
      		
      
      	# Test button	
      	def testButton( self, sender ):
      		
      		print("Test")		
      		
      
      	# Main button used to generate the animation
      	def generateAnimation( self, sender ):
      		print("Animation!")
      		
      		# ---------------------
      		# Variables
      		# ---------------------
      		# Font object
      		f = Glyphs.font
      		#print(f.selectedLayers)
      
      
      		# Selection
      		selection = f.selection
      		#print(selection)
      
      		# Frame duration 
      		fDuration = int(self.w.frameDurationUser.get())
      		# Scale
      		scaleUser = 60
      		s = scaleUser/100
      
      		# Current master ID
      		masterID = f.selectedFontMaster.id
      
      		# Randomize master's index
      		#masterIndexRandom = random.randint(0,len(f.masters))
      		#print(masterIndexRandom)
      
      
      		# Get the selected layer
      		layer = Glyphs.font.selectedLayers[f.masterIndex]
      		    
      		# String
      		userString = f.selection
      
      		# Amount of frames
      		#frames = len(f.selection)
      
      		# Frame duration
      		#fDuration = self.w.frameTextEdit.get()
      
      
      		# Page format (pixels)
      		w, h = int(str(self.w.widthUser.get())), int(str(self.w.heightUser.get()))
      
      		# Set visible nodes
      		nodesActive = True 
      
      		# Background color (CMYK)
      		bgColor = [0, .90, .86, 0] # TR Red
      
      		# Lettershapes colours (CMYK)
      		fgColor = [0, 0, 0, .2]
      
      
      		# ---------------------
      		# Functions
      		# ---------------------
      
      		# Centered glyph
      		def centeredGlyph(layer, scaleFactor, pageWidth, pageHeight):
      		    
      		    with savedState():
      		        scale(scaleFactor)
      		        layerW = layer.bounds.size.width
      		        layerH = layer.bounds.size.height
      		        
      		    
      		        newOriginX = ( pageWidth - layerW ) / 2
      		        newOriginY = ( pageHeight - layerH ) / 2
      		    
      		    #print(newOriginX, newOriginY)
      		    
      		    return(newOriginX, newOriginY)
      
      
      		# Drawing the nodes of each character
      		def drawNodes(layer, diameter, color):
      
      			radius = diameter / 2
      
      			for j, path in enumerate(layer.paths):
      			    	#print(i, path)
      				
      			    	for i, node in enumerate(path.nodes):
      			    	    xNode, yNode = node.position
      			    	    if node.type == "offcurve":
      			    	        cmykFill(*bgColor)
      			    	        strokeWidth(1)
      			    	        stroke(1)
      			    	        oval(
      			    	            xNode - radius,
      			    	            yNode - radius,
      			    	            diameter,
      			    	            diameter
      			    	            )
      			    	        cmykFill(*fgColor)		    
      			    	    elif node.type == "curve":
      			    	        fill(1)
      			    	        oval(
      			    	            xNode - radius,
      			    	            yNode - radius,
      			    	            diameter,
      			    	            diameter
      			    	            )
      			    	        cmykFill(*fgColor)		    
      				        
      			    	        # Previous 3rd point
      			    	        p3X, p3Y = path.nodes[i-3].position
      				        
      			    	        # Previous 2nd point
      			    	        p2X, p2Y = path.nodes[i-2].position
      				        
      			    	        # Previous point
      			    	        p1X, p1Y = path.nodes[i-1].position
      				        
      			    	        stroke(1)
      			    	        line(
      			    	            (p3X, p3Y),
      			    	            (p2X, p2Y)
      			    	            )
      				            
      			    	        line(
      			    	            (p1X, p1Y),
      			    	            (xNode, yNode)
      			    	            )
      				        
      			    	        stroke(None)
      				        
      			    	    else:
      			    	        fill(1)
      			    	        oval(
      			    	            xNode - radius,
      			    	            yNode - radius,
      			    	            diameter,
      			    	            diameter
      			    	            )
      			    	        cmykFill(*fgColor)		    
      
      
      
      		for g in selection:
      		    
      			newPage(w, h)
      			frameDuration(1/fDuration)
      
      			# Background
      
      			cmykFill(*bgColor)
      			rect(0,0,w,h)
      			
      
      			layer = g.layers[f.masterIndex]
      			#print(layer.parent)
      			# Generating a new page/frame
      
      			#fill(1)
      			print(layer.parent.name)
      
      			
      			#print( layer.bounds.origin.x, layer.bounds.origin.y)
      
      
      			X, Y = centeredGlyph(layer, s, w, h)
      
      			with savedState():
      			    #oval(width()/2, height()/2, 20, 20)
      				scale(s, center =(width()/2, height()/2))
      
      				translate(X-layer.bounds.origin.x , Y- layer.bounds.origin.y + layer.bounds.size.height * .06)
      
      				
      
      				if self.w.showNodes.get() == 1:
      					drawNodes(layer, 10, (0))
      					strokeWidth(1)
      					cmykStroke(0,0,0,.2)
      					cmykFill(None)
      
      					drawPath(layer.completeBezierPath)
      					print("nodes")
      					#for c in layer.components:
      					    #drawPath(c.completeBezierPath)
      
      
      				elif self.w.showNodes.get() == 0:
      					cmykFill(0,0,0,.2)
      					strokeWidth(1)
      					cmykStroke(None)
      					drawPath(layer.completeBezierPath)
      					print("not-nodes")
      
      				else:
      					print("Nodes problem")    
      					pass
      
      
      		# ---------------------
      		# Telling Drawbot the drawing is done
      		endDrawing()
      
      
      		# Closing the window
      		self.w.close()
      
      		# ································· 
      		# Saving process 
      		# ·································
      
      		# -----------------------------------
      		# Accessing the directory of the file
      		fDirectory = os.path.dirname(f.filepath) # Only the directory
      		fName = os.path.basename(f.filepath) # Only the name
      		fNameParts = os.path.splitext(fName) # Split parts
      		fPath = f.filepath
      
      		# --------------------------------------
      		# Generating a text file with the report 
      		# Assigning a format
      		self.w.popUpFormat.get()
      		listOfFormats = [".gif", ".mov", ".jpg", ".pdf"]
      
      
      		NewfName = fNameParts[0] + ' - Glyphs animation%s' % (listOfFormats[self.w.popUpFormat.get()]) # Change extension
      		NewfPath = os.path.join(fDirectory, NewfName) # Change extension
      
      		# Saving the .pdf
      		saveImage(NewfPath)
      
      
      		# ································· 
      		# Glyphs' notification
      		# ·································
      		Glyphs.showNotification('Animation generator', 'Generated animation from selection in the current font')
      
      
      		# ---------------------
      		# Test
      		# ---------------------
      		print("Done")  
      
      
      
      
      # Calling the object
      singleGlyphsAnimation()
      
      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Hello again,

      I'm again using DrawBot as a module to use it inside Glyphs and, while ths script works inside Drawbot's plugin in Glyphs, it doesn't generate the same output when I'm using it as a script.

      I'm using newDrawing() and endDrawing() but still it doesn't work.

      Any idea what it could be?

      Thanks!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: OTF file: accessing contours & segments

      Thank you so much again, Gustavo!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: OTF file: accessing contours & segments

      Thanks a lot, @gferreira!

      I knew about these attributes of a BezierPath() but since I want to know from each segment if it is a line or a curve I thought I could use a module and apply it to this BezierPath(). Anyway, I think I found a way to get this information by counting the amount of points in a segment so that, if there are 2 points it would be a straight line and if there are 3 a curve. Does this make sense?

      Thanks a lot again, Gustavo.

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • OTF file: accessing contours & segments

      Hello,

      Is there any way I could use a BezierPath() generated from an OTF file in an approach like FontParts does with UFO files?

      I would like to access more than contours, segments and points of that BezierPath() and get more attributes of it.

      Thanks!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Thanks @frederik! This was what I was missing and now it works just as I expected.

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: PDF adding pages to existing file

      Thanks for the answer, @gferreira. I'm actually saving the pdf at the very end of the script outside the loop that creates the pages.

      I'm using Drawbot inside Glyphs and, just to test it, I've run the script both using Drawbot as a module (which generates the problem) and running it with the UI inside Glyphs and it works fine.

      I still don't fully get what's going on there, do you have any idea? I could share the code if you want.

      Thanks again for your help and the link.

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • PDF adding pages to existing file

      Hello,

      I'm currently using Drawbot to generate a character set of the current font. The problem is that when saves the PDF it doesn't generate a new file but it keeps adding pages to an existing PDF in the directory.

      I'm not sure how much would help to have the whole script but for now I'm sharing the block of code that I think is causing this problem. I guess it is the way I'm saving the PDF.

      # -----------------------------------------------------
      # Accessing the directory of the file
      fDirectory = os.path.dirname(f.filepath) # Directory
      fName = os.path.basename(f.filepath) # Only the name
      fNameParts = os.path.splitext(fName) # Split parts
      fPath = f.filepath
      
      # -----------------------------------------------------
      # Generating a file with the character set 
      NewfName = fNameParts[0] + ' - Character set.pdf' # Change extension
      NewfPath = os.path.join(fDirectory, NewfName) 
      
      # Saving the .pdf
      saveImage(NewfPath)
      
      

      Thanks beforehand for any help!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • RE: Sorting glyphs by "density"

      Thanks @gferreira!

      I didn't know that there were already functions that could calculate the area of a vector. It's nice to know that I could also calculate the amount of pixels each character takes but for now I'm totally fine with your suggestion using the "density" of a BezierPath().

      I can use this useful piece of code to design what I have in mind so thanks a lot!

      posted in General Discussion
      RicardGarcia
      RicardGarcia
    • Sorting glyphs by "density"

      Hello, lately I have been thinking about using a typeface to generate some images using glyphs as "pixels" depending on whether they have less or more black. I guess the process to do so is to use a grayscale image and assign one glyph or another for each pixel depending on how light or how dark it is.

      Do you have any idea how to generate this and group glyphs, for instance, in 4 groups from lightest to darkest?

      Thanks!

      posted in General Discussion
      RicardGarcia
      RicardGarcia