Esempio n. 1
0
	def __init__( self ):
		# Window 'self.w':
		windowWidth  = 400
		windowHeight = 300
		windowWidthResize  = 1000 # user can resize width by this value
		windowHeightResize = 1000 # user can resize height by this value
		self.w = vanilla.FloatingWindow(
			( windowWidth, windowHeight ), # default window size
			"Merge Suffixed Glyphs into Color Layers", # window title
			minSize = ( windowWidth, windowHeight ), # minimum size (for resizing)
			maxSize = ( windowWidth + windowWidthResize, windowHeight + windowHeightResize ), # maximum size (for resizing)
			autosaveName = "com.mekkablue.MergeSuffixedGlyphsIntoColorLayers.mainwindow" # stores last window position and size
		)
		
		# UI elements:
		linePos, inset, lineHeight = 12, 15, 22
		
		self.w.descriptionText = vanilla.TextBox( (inset, linePos+2, -inset, 14), "Merge suffixed glyphs into the following color indexes:", sizeStyle='small', selectable=True )
		linePos += lineHeight
		
		self.w.indexToSuffix = vanilla.TextEditor( (2, linePos, -2, -110), "# Syntax: CPAL index = glyph name suffix\n# list them in chronological order (bottom-up)\n# use hashtags for comments\n0=.shadow\n2=.body\n1=.front", callback=self.SavePreferences, checksSpelling=False )
		#self.w.indexToSuffix.getNSTextEditor().setToolTip_("Syntax: colorindex=.suffix, use hashtags for comments. List them in chronological order (bottom-up). Example:\n0=.shadow\n2=.body\n1=.front")
		
		self.w.indexToSuffix.getNSScrollView().setHasVerticalScroller_(1)
		self.w.indexToSuffix.getNSScrollView().setHasHorizontalScroller_(1)
		self.w.indexToSuffix.getNSScrollView().setRulersVisible_(0)
		legibleFont = NSFont.legibileFontOfSize_(NSFont.systemFontSize())
		textView = self.w.indexToSuffix.getNSTextView()
		textView.setFont_(legibleFont)
		textView.setHorizontallyResizable_(1)
		textView.setVerticallyResizable_(1)
		textView.setAutomaticDataDetectionEnabled_(1)
		textView.setAutomaticLinkDetectionEnabled_(1)
		textView.setDisplaysLinkToolTips_(1)
		textSize = textView.minSize()
		textSize.width = 1000
		textView.setMinSize_(textSize)
		
		linePos = -105
		
		self.w.disableSuffixedGlyphs = vanilla.CheckBox( (inset, linePos-1, -inset, 20), "Deactivate export for glyphs with listed suffixes", value=True, callback=self.SavePreferences, sizeStyle='small' )
		linePos += lineHeight
		
		self.w.deletePreexistingColorLayers = vanilla.CheckBox( (inset, linePos-1, -inset, 20), "Delete preexisting Color layers in target glyphs", value=True, callback=self.SavePreferences, sizeStyle='small' )
		linePos += lineHeight
		
		self.w.processCompleteFont = vanilla.CheckBox( (inset, linePos-1, -inset, 20), "Process complete font (otherwise only add into selected glyphs)", value=False, callback=self.SavePreferences, sizeStyle='small' )
		linePos += lineHeight
		
		# Run Button:
		self.w.runButton = vanilla.Button( (-80-inset, -20-inset, -inset, -inset), "Merge", sizeStyle='regular', callback=self.MergeSuffixedGlyphsIntoColorLayersMain )
		# self.w.setDefaultButton( self.w.runButton )
		
		# Load Settings:
		if not self.LoadPreferences():
			print("Note: 'Merge Suffixed Glyphs into Color Layers' could not load preferences. Will resort to defaults")
		
		# Open window and focus on it:
		self.w.open()
		self.w.makeKey()
Esempio n. 2
0
    def __init__(self, dimensions, font):
        font_name = font.info.familyName or ""
        attribution = "{} by {}".format(font_name,
                                        font.info.openTypeNameDesigner)
        attribution_attributes = {
            NSFontAttributeName:
            NSFont.systemFontOfSize_(NSFont.systemFontSize()),
            NSForegroundColorAttributeName: NSColor.whiteColor()
        }
        formatted_attribution = NSMutableAttributedString.alloc(
        ).initWithString_attributes_(attribution, attribution_attributes)
        formatted_attribution.addAttribute_value_range_(
            NSFontAttributeName,
            NSFont.boldSystemFontOfSize_(NSFont.systemFontSize()),
            [0, len(font_name)])

        super(AttributionText, self).__init__(dimensions,
                                              formatted_attribution)
    def __init__(self, dimensions, font):
        font_name = font.info.familyName
        attribution = "{} by {}".format(font_name, font.info.designer)
        attribution_attributes = {
            NSFontAttributeName: NSFont.systemFontOfSize_(NSFont.systemFontSize()),
            NSForegroundColorAttributeName: NSColor.whiteColor()
        }
        formatted_attribution = NSMutableAttributedString.alloc().initWithString_attributes_(attribution, attribution_attributes)
        formatted_attribution.addAttribute_value_range_(NSFontAttributeName, NSFont.boldSystemFontOfSize_(NSFont.systemFontSize()), [0, len(font_name)])

        super(AttributionText, self).__init__(dimensions, formatted_attribution)
Esempio n. 4
0
def font(fontName, fontSize=None):
	# Set the font by PostScript name.
	# Optionally set the font size.
	if fontSize is None:
		fontSize = NSFont.systemFontSize()
	NSFont.fontWithName_size_(fontName, fontSize)
Esempio n. 5
0
	path = glyph._layer.bezierPath
	drawPath(path)

def save():
	# save the current graphic state 
	NSGraphicsContext.currentContext().saveGraphicsState()
	
def restore():
	# restore the current graphic state 
	NSGraphicsContext.currentContext().restoreGraphicsState()

currentPath = None
currentFillColor = NSColor.blackColor()
currentStrokeColor = None
currentGradient = None
currentFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())

def rect(x, y, width, height):
	# draws a rectangle 
	drawPath(NSBezierPath.bezierPathWithRect_(NSMakeRect(x, y, width, height)))
	
def oval(x, y, width, height):
	# draws an oval
	drawPath(NSBezierPath.bezierPathWithOvalInRect_(NSMakeRect(x, y, width, height)))
	
def line(x1, y1, x2=None, y2=None):
	# draws a line
	if x2 is None and y2 is None and isinstance(x1, tuple) and isinstance(y1, tuple):
		(x1, y1), (x2, y2) = x1, y1
	p = NSBezierPath.bezierPath()
	p.moveToPoint_(NSMakePoint(x1, y1))
Esempio n. 6
0
    def __init__(self):
        # Window 'self.w':
        windowWidth = 380
        windowHeight = 160
        windowWidthResize = 500  # user can resize width by this value
        windowHeightResize = 600  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Axis Mapper",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.AxisMapper.mainwindow"  # stores last window position and size
        )

        # UI elements:
        linePos, inset, lineHeight = 4, 10, 22

        self.w.descriptionText = vanilla.TextBox(
            (inset, linePos + 2, -inset, 14),
            "Axis Mapping from user-visible (not native) values:",
            sizeStyle='small',
            selectable=True)
        linePos += lineHeight

        self.w.axisPicker = vanilla.ComboBox((inset, linePos - 1, 60, 20),
                                             self.AxisListForFrontmostFont(),
                                             callback=self.SavePreferences,
                                             sizeStyle='small')
        self.w.axisPicker.getNSComboBox().setToolTip_(
            "Pick or type the 4-letter tag of the axis for which you want to edit the mapping."
        )
        self.w.axisReset = vanilla.SquareButton((inset + 65, linePos, 20, 18),
                                                "↺",
                                                sizeStyle='small',
                                                callback=self.resetAxisList)
        self.w.axisReset.getNSButton().setToolTip_(
            "Will populate the axis picker with the tags for all axes in the frontmost font."
        )

        self.w.minText = vanilla.TextBox((inset + 100, linePos + 2, 55, 14),
                                         "Axis Min:",
                                         sizeStyle='small',
                                         selectable=True)
        self.w.minValue = vanilla.EditText(
            (inset + 100 + 55, linePos - 1, 40, 19),
            self.MinimumForCurrentAxis(),
            callback=self.SavePreferences,
            sizeStyle='small')
        tooltipText = "User-visible slider minimum, typically set with an Axis Location parameter. Not (necessarily) the native master value."
        self.w.minText.getNSTextField().setToolTip_(tooltipText)
        self.w.minValue.getNSTextField().setToolTip_(tooltipText)
        self.w.minValueReset = vanilla.SquareButton(
            (inset + 100 + 60 + 40, linePos, 20, 18),
            "↺",
            sizeStyle='small',
            callback=self.resetMinimum)
        self.w.minValueReset.getNSButton().setToolTip_(
            "Will attempt to guess the user-visible slider minimum of the frontmost font."
        )

        self.w.maxText = vanilla.TextBox((inset + 230, linePos + 2, 55, 14),
                                         "Axis Max:",
                                         sizeStyle='small',
                                         selectable=True)
        self.w.maxValue = vanilla.EditText(
            (inset + 230 + 55, linePos - 1, 40, 19),
            self.MaximumForCurrentAxis(),
            callback=self.SavePreferences,
            sizeStyle='small')
        tooltipText = "User-visible slider maximum, typically set with an Axis Location parameter. Not (necessarily) the native master value."
        self.w.maxText.getNSTextField().setToolTip_(tooltipText)
        self.w.maxValue.getNSTextField().setToolTip_(tooltipText)
        self.w.maxValueReset = vanilla.SquareButton(
            (inset + 230 + 60 + 40, linePos, 20, 18),
            "↺",
            sizeStyle='small',
            callback=self.resetMaximum)
        self.w.maxValueReset.getNSButton().setToolTip_(
            "Will attempt to guess the user-visible slider maximum of the frontmost font."
        )
        linePos += lineHeight

        self.w.mappingRecipe = vanilla.TextEditor(
            (0, linePos, -0, -20 - inset * 2),
            text=fallbackText.strip(),
            callback=self.SavePreferences,
            checksSpelling=False)
        legibleFont = NSFont.legibileFontOfSize_(NSFont.systemFontSize())
        textView = self.w.mappingRecipe.getNSTextView()
        textView.setFont_(legibleFont)

        # Buttons:
        self.w.recipeButton = vanilla.Button((inset, -20 - inset, 120, -inset),
                                             "Reset Recipe",
                                             sizeStyle='regular',
                                             callback=self.ResetRecipe)
        self.w.recipeButton.getNSButton().setToolTip_(
            "Construct a fallback axis mapping recipe for axis and the min/max values above, based on the existing active instances. Can be a good start for creating new mappings. Respects the weightClass settings for the 'wght' axis."
        )

        self.w.extractButton = vanilla.Button(
            (inset + 130, -20 - inset, 120, -inset),
            "Extract Recipe",
            sizeStyle='regular',
            callback=self.ExtractAxisMapping)
        self.w.extractButton.getNSButton().setToolTip_(
            "Extract the axis mapping recipe for the chosen axis from an existing Axis Mappings parameter, and into the min/max values specified above. Will do nothing if it fails. Great for editing existing mappings."
        )

        self.w.runButton = vanilla.Button(
            (-80 - inset, -20 - inset, -inset, -inset),
            "Map",
            sizeStyle='regular',
            callback=self.AxisMapperMain)
        self.w.runButton.getNSButton().setToolTip_(
            "Write the current mapping recipe into an Axis Mappings parameter for the frontmost font."
        )
        self.w.setDefaultButton(self.w.runButton)

        # Load Settings:
        if not self.LoadPreferences():
            print(
                "Note: 'Axis Mapper' could not load preferences. Will resort to defaults"
            )

        # Open window and focus on it:
        self.w.open()
        self.w.makeKey()
Esempio n. 7
0
    def __init__(self):
        # Window 'self.w':
        windowWidth = 550
        windowHeight = 260
        windowWidthResize = 1000  # user can resize width by this value
        windowHeightResize = 1000  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Encoding Converter",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.EncodingConverter.mainwindow"  # stores last window position and size
        )

        # UI elements:
        linePos, inset, lineHeight = 8, 15, 22

        self.w.descriptionText = vanilla.TextBox(
            (inset, linePos + 2, -inset, 14),
            "Enter conversion text (see tooltips):",
            sizeStyle='small',
            selectable=True)
        linePos += lineHeight

        self.w.recipe = vanilla.TextEditor((1, linePos, -1, -inset * 3),
                                           text="",
                                           callback=self.SavePreferences,
                                           checksSpelling=False)
        self.w.recipe.getNSTextView().setToolTip_(
            "- Freely write comments and empty lines\n- Rename: Lines containing a dash (-) followed by a greater sign (>) will trigger glyph renaming, with or without spaces between names\n- Recipe: Lines containing glyph recipes with plus (+) and equals (=) will be treated like in Glyph > Add Glyphs... as long as the do not contain any space\n- Recipes will overwrite existing glyphs. Renamings will create a number-suffixed glyph if a glyph with the same name already exists."
        )
        self.w.recipe.getNSScrollView().setHasVerticalScroller_(1)
        self.w.recipe.getNSScrollView().setHasHorizontalScroller_(1)
        self.w.recipe.getNSScrollView().setRulersVisible_(0)

        legibleFont = NSFont.legibileFontOfSize_(NSFont.systemFontSize())
        textView = self.w.recipe.getNSTextView()
        textView.setFont_(legibleFont)
        textView.setHorizontallyResizable_(1)
        textView.setVerticallyResizable_(1)
        textView.setAutomaticDataDetectionEnabled_(1)
        textView.setAutomaticLinkDetectionEnabled_(1)
        textView.setDisplaysLinkToolTips_(1)
        textSize = textView.minSize()
        textSize.width = 1000
        textView.setMinSize_(textSize)
        # textView.textContainer().setWidthTracksTextView_(0)
        # textView.textContainer().setContainerSize_(textSize)

        # Run Button:
        self.w.openButton = vanilla.Button((inset, -20 - inset, 110, -inset),
                                           "Open Text…",
                                           sizeStyle='regular',
                                           callback=self.importEncoding)
        self.w.saveButton = vanilla.Button(
            (inset + 120, -20 - inset, 110, -inset),
            "Save Text…",
            sizeStyle='regular',
            callback=self.exportEncoding)
        self.w.resetButton = vanilla.Button(
            (inset + 260, -20 - inset, 100, -inset),
            "Reset Text",
            sizeStyle='regular',
            callback=self.resetEncoding)
        self.w.runButton = vanilla.Button(
            (-120 - inset, -20 - inset, -inset, -inset),
            "Convert Font",
            sizeStyle='regular',
            callback=self.EncodingConverterMain)
        self.w.setDefaultButton(self.w.runButton)

        # Load Settings:
        if not self.LoadPreferences():
            print(
                "Note: 'Encoding Converter' could not load preferences. Will resort to defaults"
            )

        # Open window and focus on it:
        self.w.open()
        self.w.makeKey()
Esempio n. 8
0
    def openWindow(self):
        w = FloatingWindow((200, 242), title="Backdrop", closable=False)
        w.glyphList = List((10, 10, -10, 160), [{
            "Visibility": False,
            "Status": None,
            "Name": "None",
            "Position": 0,
            "layer": None
        }],
                           columnDescriptions=[{
                               "title": "Visibility",
                               "cell": CheckBoxListCell(),
                               "width": 30
                           }, {
                               "title": "Status",
                               "width": 20,
                               "editable": False
                           }, {
                               "title": "Name",
                               "width": 80,
                               "editable": False
                           }, {
                               "title": "Position",
                               "width": 30
                           }, {
                               "title": "layer",
                               "width": -3,
                               "editable": False
                           }],
                           showColumnTitles=False,
                           rowHeight=20,
                           drawFocusRing=False,
                           enableDelete=True,
                           editCallback=self.listEdited)
        w.addGlyphButton = Button((10, 180, 90, 20),
                                  "Add Glyph",
                                  callback=self.glyphPopover)
        w.transLeftButton = Button((128, 180, 30, 20),
                                   u"←",
                                   callback=self.moveLeft)
        w.transRightButton = Button((160, 180, 30, 20),
                                    u"→",
                                    callback=self.moveRight)
        w.alignButton = SegmentedButton(
            (10, 209, -7, 21),
            [dict(title=u"􀌀"),
             dict(title=u"􀌁"),
             dict(title=u"􀌂")],
            callback=self.changeAlignment,
            selectionStyle="one")
        w.alignButton.set(self.alignment)
        w.open()

        fm = NSFontManager.sharedFontManager()
        systemFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())
        self.italicFont = fm.fontWithFamily_traits_weight_size_(
            systemFont.fontName(), NSItalicFontMask, 5, systemFont.pointSize())
        self.boldFont = fm.fontWithFamily_traits_weight_size_(
            systemFont.fontName(), NSUnitalicFontMask, 8,
            systemFont.pointSize())

        self.currentWindow = w
        self.toolStatus = True
        try:
            self.currentGlyph = Glyphs.font.selectedLayers[0]
        except:
            pass

        self.refreshGL()
        self.updateWindowUI()
Esempio n. 9
0
def font(fontName, fontSize=None):
    # Set the font by PostScript name.
    # Optionally set the font size.
    if fontSize is None:
        fontSize = NSFont.systemFontSize()
    NSFont.fontWithName_size_(fontName, fontSize)
Esempio n. 10
0
def save():
    # save the current graphic state
    NSGraphicsContext.currentContext().saveGraphicsState()


def restore():
    # restore the current graphic state
    NSGraphicsContext.currentContext().restoreGraphicsState()


currentPath = None
currentFillColor = NSColor.blackColor()
currentStrokeColor = None
currentGradient = None
currentStrokeWidth = None
currentFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())


def rect(x, y, width, height):
    # draws a rectangle
    drawPath(NSBezierPath.bezierPathWithRect_(NSMakeRect(x, y, width, height)))


def oval(x, y, width, height):
    # draws an oval
    drawPath(
        NSBezierPath.bezierPathWithOvalInRect_(NSMakeRect(x, y, width,
                                                          height)))


def line(x1, y1, x2=None, y2=None):