def Fill_Halftone(self, thislayer): components = [] for size in range(0,5): font = self.font shapename = "pixel"+str(size) if font.glyphs[shapename]: del font.glyphs[shapename] ng = GSGlyph() ng.name = shapename ng.category = "Mark" ng.export = True font.glyphs.append(ng) firstmaster = font.masters[0].id thislayer = GSLayer() thislayer.layerId = thislayer.associatedMasterId =firstmaster ng.layers[firstmaster] = thislayer thislayer.width = 0 ox, oy = 0, 0 w, h = 40, 40 grid = 10 unit = 5 if size!=0: gridx = 10 * size gridy = gridx else: gridx = 10 gridy = 5 x, y = ox, oy switchx = False for x in range(ox, ox+w, gridx): for y in range(oy, oy+h, gridy): if switchx==True: if size==0: adjust = 5 switchx = not switchx else: adjust = gridx/2 switchx = not switchx else: adjust=0 switchx = not switchx ns = drawRectangle( x + adjust, y , unit, unit) thislayer.paths.append(ns) switchx = False components.append(ng) return components
def _get_indic_rightmost_stem(self, l): stem_center = None number_of_samples = 12 stem_width = self._indic_stem_widths.get(l.parent.script, {}).get(l.associatedMasterId) if stem_width is None: return fuzziness = stem_width * 0.1 measure_interval = int(l.bounds.size.height / number_of_samples) measure_heights = range(int(l.bounds.origin.y), int(l.bounds.origin.y + l.bounds.size.height), measure_interval) potential_stems = defaultdict(list) measured_points = [] # l.guides = [] for height in measure_heights: for p in l.paths: measure_l = GSLayer() measure_l.width = l.width measure_l.paths.append(p) measured_points.append(measure_l.intersectionsBetweenPoints((0, height), (measure_l.width, height), components=True)[1:-1]) for c in l.components: measure_l = c.componentLayer.copyDecomposedLayer() measure_l.removeOverlap() measure_l.applyTransform(c.transform) measured_points.append(measure_l.intersectionsBetweenPoints((0, height), (measure_l.width + c.transform[4], height), components=True)[1:-1]) # if 1: # ngl = GSGuideLine() # ngl.position = NSPoint(0, height) # ngl.setShowMeasurement_(1) # l.guides.append(ngl) # print(l, stem_width) for measure_coords in measured_points: for ci, coord in enumerate(measure_coords): try: next_coord = measure_coords[ci + 1] except IndexError: break coord_distance = next_coord.x - coord.x # print(coord_distance, measure_coords) if self._check_coord(coord_distance, stem_width, fuzziness=fuzziness): stem_mid_point = round((next_coord.x + coord.x) / 2) stem_mid_point_max = stem_mid_point + fuzziness stem_mid_point_min = stem_mid_point - fuzziness added = False for min_max in potential_stems.keys(): pmin, pmax = min_max if pmax > stem_mid_point_max > pmin or pmax > stem_mid_point_min > pmin: potential_stems[min_max].append(stem_mid_point) added = True break if not added: potential_stems[(stem_mid_point_min, stem_mid_point_max)].append(stem_mid_point) vals = potential_stems.values() vals.sort(reverse=True) vals.sort(key=len, reverse=True) stem_center = round(sum(vals[0]) / len(vals[0])) return stem_center