Example #1
0
        void ProcessLine(QString line, int level, const Location &location, bool &inComment)
        {
            if (m_debug) Out(QString("Line (level %1): %2").arg(level).arg(line));

            // remove comments, etc.
            line = SimplifyLine(line, inComment); 
            if (line.isEmpty()) return;

            // process includes
            if (line.startsWith(CInclude)) 
            {
                ProcessInclude(line, level + 1, location);
                return;
            }

            // process defines
            line = m_defs.ProcessLine(line);
            
            if (line.isEmpty()) return;

            // save
            int cmdNum = m_result.size() + 1;
            m_result.push_back(DRIFileLoad::RawCommand(line, cmdNum, 
                                                       location.File, location.Line));
        }
Example #2
0
void ZinniaProcess(void* ud, pt_t* points, int nPoints) {
	Zinnia* zn = (Zinnia*) ud;
	// clear the last result
	if(zn->result != NULL) {
		zinnia_result_destroy(zn->result);
		zn->result = NULL;
	}
	// get bounding box
	short xmin=SHRT_MAX,xmax=SHRT_MIN,ymin=SHRT_MAX,ymax=SHRT_MIN;
	for(int i=0; i<nPoints; ++i) {
		if(PT_ISVALID(points[i])) {
			if(points[i].x > xmax) xmax = points[i].x;
			if(points[i].x < xmin) xmin = points[i].x;
			if(points[i].y > ymax) ymax = points[i].y;
			if(points[i].y < ymin) ymin = points[i].y;
		}
	}
	// add some margin
	ymin -= 4;
	xmin -= 4;
	ymax += 4;
	xmax += 4;
	// determine scaling factors
	float sf;
	if(xmax - xmin > ymax - ymin) {
		sf = 300.0 / (xmax - xmin);
		ymin = 0;
	} else {
		sf = 300.0 / (ymax - ymin);
		xmin = 0;
	}
	// the stroke index
	size_t id = 0;
	// create a new character
	zinnia_character_t *character = zinnia_character_new();
	zinnia_character_clear(character);
	zinnia_character_set_width(character, 300);
	zinnia_character_set_height(character, 300);
	// the index in the point array from which this stroke begins
	int from = 0;
	for(int i=0; i<nPoints; ++i) {
		// If we get to a stroke break, do the magic
		if(!PT_ISVALID(points[i])) {
			pt_t* simplified = 0;
			// Simplify the line we have so far. An epsilon of 6 is a guess,
			// it probably should be determined based on xmax,xmin,ymax,ymin
			int n = SimplifyLine(&points[from],i-from,&simplified,6);
			// Add the scaled stroke to the zinnia character
			for(int j=0;j<n;++j)
				zinnia_character_add(character, id, sf * (simplified[j].x - xmin), sf * (simplified[j].y - ymin));
			// clear the simplified stroke memory
			free(simplified);
			// advance to the next stroke
			id++;
			from = i+1;
		}
	}

	zn->result = zinnia_recognizer_classify(zn->recog, character, 10);
	if (zn->result == NULL) {
		FcitxLog(ERROR, "Could not classify character");
		return;
	}

	zinnia_character_destroy(character);
}