|
From: JustFillBug <moz...@ya...> - 2008-12-06 09:05:13
|
On 2008-12-05, George Williams <gw...@si...> wrote:
>>
>> I want to replace part of a glyph with another glyph without changing
>> its shape. This is basically what the replaceWithReference does.
> Find/Replace will do that too.
>
I tried Find/Replace and I use a smaller splineline for both the Search
and Replace patterns, turns on scale. After Replace All, bigger
splinelines are changed to even smaller splinelines.
>> Could you add a flag option to the find() to let user specify finding
> Nope. I am swamped. But you may.
OK, here's the patch. I don't know which other fields in SearchData are
useful.
Index: htdocs/python.html
===================================================================
RCS file: /cvsroot/fontforge/fontforge/htdocs/python.html,v
retrieving revision 1.71
diff -u -r1.71 python.html
--- htdocs/python.html 10 Nov 2008 04:11:45 -0000 1.71
+++ htdocs/python.html 6 Dec 2008 08:28:08 -0000
@@ -3453,9 +3453,21 @@
</TR>
<TR>
<TD><CODE><A NAME="font-find">find</A></CODE></TD>
- <TD><CODE>(contour[,error-bound])</CODE></TD>
+ <TD><CODE>(contour[,error-bound,search_flags])</CODE></TD>
<TD>Searches the font for all glyphs containing the contour (or layer) and
- returns an iterator which returns those glyphs.</TD>
+ returns an iterator which returns those glyphs.<P>
+ error-bound: defaults to 0.01.<BR>
+ search_flags: tuple of the strings: reverse, flips, rotate, scale.<P>
+
+ When found, the glyph.temporary is set to a dict of:
+ <pre>
+ {
+ "findMatchedRefs": matched_refs_bit_map,
+ "findMatchedContours": matched_contours_bit_map,
+ "findMatchedContoursStart": matched_contours_start_bit_map,
+ }
+ </pre>
+ </TD>
</TR>
<TR>
<TD><CODE>findEncodingSlot</CODE></TD>
Index: fontforge/python.c
===================================================================
RCS file: /cvsroot/fontforge/fontforge/fontforge/python.c,v
retrieving revision 1.151
diff -u -r1.151 python.c
--- fontforge/python.c 4 Dec 2008 04:31:50 -0000 1.151
+++ fontforge/python.c 6 Dec 2008 08:28:26 -0000
@@ -7844,8 +7844,33 @@
static PyObject *fontiter_iternextkey(fontiterobject *di) {
if ( di->sv!=NULL ) {
SplineChar *sc = SDFindNext(di->sv);
- if ( sc!=NULL )
-return( PySC_From_SC_I( sc ) );
+ if ( sc!=NULL ) {
+#ifdef _HAS_LONGLONG
+ const char *dictfmt = "{sKsKsK}";
+#else
+ const char *dictfmt = "{sksksk}"
+#endif
+ PyObject *glyph, *tempdict;
+ PyObject *matched;
+ glyph = PySC_From_SC_I( sc );
+ /* Fill matched result into the glyph.temporary atribute. */
+ tempdict = PyFF_Glyph_get_temporary((PyFF_Glyph *)glyph, NULL);
+ if (tempdict == NULL || !PyDict_Check(tempdict)) {
+ tempdict = PyDict_New();
+ PyFF_Glyph_set_temporary((PyFF_Glyph *)glyph, tempdict, NULL);
+ }
+
+ matched = Py_BuildValue(dictfmt,
+ "findMatchedRefs", di->sv->matched_refs,
+ "findMatchedContours", di->sv->matched_ss,
+ "findMatchedContoursStart", di->sv->matched_ss_start
+ );
+ PyDict_Update(tempdict, matched);
+ Py_DECREF(tempdict);
+ Py_DECREF(matched);
+
+return( glyph );
+ }
} else switch ( di->byselection ) {
case 0: {
SplineFont *sf = di->sf;
@@ -11372,13 +11397,24 @@
return( Py_BuildValue( "i", FVReplaceAll(fv,srch_ss,rpl_ss,err,sv_reverse|sv_flips)));
}
+struct flaglist find_flags[] = {
+ {"reverse", sv_reverse},
+ {"flips", sv_flips},
+ {"rotate", sv_rotate},
+ {"scale", sv_scale},
+ {"endpoints", sv_endpoints},
+ NULL,
+};
+
static PyObject *PyFFFont_find(PyObject *self, PyObject *args) {
FontViewBase *fv = ((PyFF_Font *) self)->fv;
PyObject *srch;
SplineSet *srch_ss;
+ PyObject *pyflags = NULL;
+ int flags = 0;
double err = .01;
- if ( !PyArg_ParseTuple(args,"O|d", &srch, &err ))
+ if ( !PyArg_ParseTuple(args,"O|dO", &srch, &err, &pyflags))
return( NULL );
if ( PyType_IsSubtype(&PyFF_LayerType,srch->ob_type) ) {
@@ -11389,9 +11425,13 @@
PyErr_Format(PyExc_TypeError, "Unexpected type");
return( NULL );
}
+ if (pyflags)
+ flags = FlagsFromTuple(pyflags, find_flags);
+ else
+ flags = sv_reverse|sv_flips;
/* srch_ss will be freed when the iterator dies */
-return( fontiter_New( self,false,SDFromContour(fv,srch_ss,err,sv_reverse|sv_flips)) );
+return( fontiter_New( self,false,SDFromContour(fv,srch_ss,err,flags)) );
}
static PyObject *PyFFFont_glyphs(PyObject *self, PyObject *args) {
Index: fontforge/search.c
===================================================================
RCS file: /cvsroot/fontforge/fontforge/fontforge/search.c,v
retrieving revision 1.53
diff -u -r1.53 search.c
--- fontforge/search.c 24 Aug 2008 02:40:17 -0000 1.53
+++ fontforge/search.c 6 Dec 2008 08:28:27 -0000
@@ -1324,10 +1324,10 @@
sv->fudge_percent = .001;
sv->fudge = fudge;
- sv->tryreverse = (flags&sv_reverse);
- sv->tryflips = (flags&sv_flips);
- sv->tryrotate = (flags&sv_rotate);
- sv->tryscale = (flags&sv_scale);
+ sv->tryreverse = (flags&sv_reverse) > 0;
+ sv->tryflips = (flags&sv_flips) > 0;
+ sv->tryrotate = (flags&sv_rotate) > 0;
+ sv->tryscale = (flags&sv_scale) > 0;
sv->sc_srch.layers[ly_fore].splines = find;
sv->sc_srch.changed_since_autosave = sv->sc_rpl.changed_since_autosave = true;
|