Skip to content

Instantly share code, notes, and snippets.

View adrientetar's full-sized avatar

Adrien Tétar adrientetar

View GitHub Profile
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.FocusInteraction
import androidx.compose.foundation.interaction.HoverInteraction
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
from collections.abc import Collection
from dataclasses import dataclass, field
from typing import Dict, List, Tuple
@dataclass
class Point:
_x: int
_y: int
_type: str
import cProfile
def profile_defcon():
from defcon import Font
pr = cProfile.Profile()
pr.enable()
font = Font("Roboto-Regular.ufo")
for glyph in font:
for contour in glyph:
@adrientetar
adrientetar / ufoLib.md
Last active December 26, 2019 14:13
Technical note on the design of a new UFO library.

Thoughts on fontTools.ufoLib

w.r.t. my experience with defcon and ufoLib. Some of the functionality I discuss (notifications, etc.) definitely shouldn't go into fontTools however we ought to make fontTools.ufoLib "compatible" with these extra features. I'm sure we can do simple and versatile.

IMO fontTools.ufoLib should basically be written from scratch (with copy-pasting here and there) since ufoLib/defcon have significant bloat and apparently we want to use lxml.

General comments

Avoid the check-and-use pattern

@adrientetar
adrientetar / prof.md
Last active December 26, 2019 14:14

Here are my findings after profiling the loading of Roboto-Regular.ufo.

Setting Lib objects into the Glyph-s is expensive (10%)

  • the Lib.update(...) call is expensive (4.9%), mainly because of postNotification and _set_dirty
  • creating Lib is expensive, mainly because of beginSelfNotificationObservation (3.4%), _get_dispatcher is a large contributor of the time spent (2.5%) as it does a chain of calls from getfont to getlayerset to getlayer
  • _set_dirty (0.5%)

Solution

pip3 install PyQt5
git clone https://github.com/trufont/trufont
cd trufont
pip3 install -r requirements.txt
python3 setup.py install
trufont
@adrientetar
adrientetar / drawAsPNG.py
Last active June 19, 2016 06:31
Painting glyph with points into an SVG.
from defconQt.tools import drawing
from PyQt5.QtCore import QRect, QSize, Qt
from PyQt5.QtGui import QPainter
from PyQt5.QtSvg import QSvgGenerator
from PyQt5.QtWidgets import QApplication, QFileDialog
import os
def _currentFontSelection():
"""
We should probably have font.selection sometimes, but for now this will do.
from fontTools.feaLib.error import FeatureLibError
import traceback
font = CurrentFont()
try:
font.getRepresentation("defconQt.TTFont")
except FeatureLibError as e:
traceback.print_exc()
print(e.location)
@adrientetar
adrientetar / btree.py
Last active October 22, 2021 12:33
A simple tree implementation in Python using a list.
"""
A simple btree implementation in Python.
Python 3.3+
"""
class Node:
__slots__ = ['left', 'right', 'value']
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Codec:
def serialize(self, root):