Esempio n. 1
0
void UK2MPM_comp(int runNumberORoctet, Float_t EnWinLow, Float_t EnWinHigh) {

    gStyle->SetOptStat(0);

    TChain *mpmTree = new TChain("phys");
    TChain *ukTree = new TChain("pass4");

    std::string pdfFileBase;
    std::string mpmData;
    std::string ukData;

    if (runNumberORoctet<16000) {
        pdfFileBase = "calibrationRunComp_Octet"+itos(runNumberORoctet)+"_evis_"+itos((int)EnWinLow)+"-"+itos((int)EnWinHigh)+".pdf";
        std::string octFile = std::string(getenv("OCTET_LIST"))+"/All_Octets/octet_list_"+itos(runNumberORoctet)+".dat";
        ifstream runs(octFile.c_str());
        cout << "Opened " << octFile << "\n";
        std::string type;
        int run;
        while (runs >> type >> run) {
            if (type=="A2" || type=="A5" || type=="A7" || type=="A10" || type=="B2" || type=="B5" || type=="B7" || type=="B10") {
                mpmData = std::string(getenv("UCNAOUTPUTDIR"))+"/hists/spec_" + itos(run) + ".root";
                ukData = std::string(getenv("REPLAY_PASS4"))+"/replay_pass4_" + itos(run) + ".root";
                mpmTree->Add(mpmData.c_str());
                ukTree->Add(ukData.c_str());
                cout << "Added " << ukData << " to chain\n";
            }
        }
    }
Esempio n. 2
0
int main(int argc, char *argv[]) 
{
    int i, j, k, l, c;
    hand_t hand;
    score_t sc = -1;
    scanf("%d %d %d %d %d", &i, &j, &k, &l, &c);
    hand = (hand_t) {.cards[0] = i, .cards[1] = j, .cards[2] = k,
        .cards[3] = l, .crib = c};

#   ifdef   TEST_PAIRS
        sc = pairs(&hand);
#   elif    TEST_FIFTEENS
        sc = fifteens(&hand);
#   elif    TEST_RUNS
        sc = runs(&hand);
#   elif    TEST_RIGHTJACK
        sc = right_jack(&hand);
#   elif    TEST_SCORE
        sc = score(&hand);
#   elif    TEST_TYPE
        //fprintf(stderr, "Using card: %d\n", hand.cards[0]);
        sc = type(hand.cards[0]);
        //fprintf(stderr, "Type: %d\n", sc);
#   elif    TEST_VALUES
        fprintf(stderr, "Using card: %d\n", hand.cards[4]);
        sc = value(hand.cards[4]);
        fprintf(stderr, "Value: %d\n", sc);
#   endif /* TEST_* */
    printf("%d\n", (int) sc);
    return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    atexit(free_memory);
    /* program starts here */
    if(argc<=1) {
        /* there are no arguments, so run the shell */
        shell("LISP");
    } else {
        /* open each file (arg as filename) and run it. */
        FILE *afile=NULL;
        char str[1024];
        int32 i;
        for(i=1; i<argc; i++,afile=NULL) {
            if((afile = fopen(argv[i],"r"))!=NULL) {
                while(fgets(str,1024,afile)!=NULL) {
                    str[strlen(str)-1] = '\0';
                    runs(str);
                }
                fclose(afile);
            } else
                printf("\nCould not open file: %s\n",argv[i]);
        }
    }
    return EXIT_SUCCESS;
}
Esempio n. 4
0
	static ParagraphLayouter *GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &fontMapping)
	{
		int32 length = buff_end - buff;

		if (length == 0) {
			/* ICU's ParagraphLayout cannot handle empty strings, so fake one. */
			buff[0] = ' ';
			length = 1;
			fontMapping.End()[-1].first++;
		}

		/* Fill ICU's FontRuns with the right data. */
		FontRuns runs(fontMapping.Length());
		for (FontMap::iterator iter = fontMapping.Begin(); iter != fontMapping.End(); iter++) {
			runs.add(iter->second, iter->first);
		}

		LEErrorCode status = LE_NO_ERROR;
		/* ParagraphLayout does not copy "buff", so it must stay valid.
		 * "runs" is copied according to the ICU source, but the documentation does not specify anything, so this might break somewhen. */
		ParagraphLayout *p = new ParagraphLayout(buff, length, &runs, NULL, NULL, NULL, _current_text_dir == TD_RTL ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, false, status);
		if (status != LE_NO_ERROR) {
			delete p;
			return NULL;
		}

		return new ICUParagraphLayout(p);
	}
Esempio n. 5
0
void shell(char *name)
{
	setaddress("i");
	setaddress("am");
	setaddress("arjun");
	getaddress("yes");
	deladdress("am");
	deladdress("i");
	setaddress("menon");
	getaddress("arjun");

	char str[STR_MAX];
	puts(name);
	while(1) {
		printf("\n$ ");
		fflush(stdin);
		fgets(str,STR_MAX,stdin);
		str[strlen(str)-1] = '\0';
		trims(str,' ');
		trims(str,'\t');
		if(!strlen(str)) continue;
		if(!stricmp(str,"exit")) break;
		runs(str);
	}
}
Esempio n. 6
0
TEST(RandTest, test_runs_not1)
{
  unsigned char testbuf[16] = {0xaa, 0xaa, 0xbb, 0xff,
                               0x9f, 0xff, 0xff, 0x00,
                               0xff, 0xff, 0xff, 0x00,
                               0xaa, 0xaa, 0x00, 0x00};
  TEST_ASSERT_FLOAT_WITHIN(0.1, 0.01, runs(testbuf, 16));
}
Esempio n. 7
0
TEST(RandTest, test_runs_rand1)
{
  unsigned char testbuf[16] = {0xc1, 0xaf, 0x5d, 0xdd,
                               0xd9, 0x61, 0x03, 0xc9,
                               0x54, 0x87, 0xd7, 0x61,
                               0x13, 0xf2, 0x63, 0x20};
  TEST_ASSERT_FLOAT_WITHIN(0.1, 0.48, runs(testbuf, 16));
}
Esempio n. 8
0
TEST(RandTest, test_runs_rand2)
{
  unsigned char testbuf[16] = {0x1e, 0xbf, 0xeb, 0x16,
                               0xd8, 0x25, 0xdb, 0xc4,
                               0x02, 0x6a, 0x2f, 0x49,
                               0x14, 0x91, 0x1c, 0x51};
  TEST_ASSERT_FLOAT_WITHIN(0.1, 0.35, runs(testbuf, 16));
}
std::vector<Layout::ScanlineMaker::ScanRun> Layout::InfiniteScanlineMaker::makeScanline(Layout::LineHeight const &line_height)
{
    std::vector<ScanRun> runs(1);
    runs[0].x_start = _x;
    runs[0].x_end = FLT_MAX;   // we could use DBL_MAX, but this just seems safer
    runs[0].y = _y;
    _current_line_height = line_height;
    return runs;
}
Esempio n. 10
0
void text_itemizer::itemize_script()
{
    script_runs_.clear();

    ScriptRun runs(text_.getBuffer(), text_.length());
    while (runs.next())
    {
        script_runs_.emplace_back(runs.getScriptCode(), runs.getScriptStart(), runs.getScriptEnd());
    }
}
Esempio n. 11
0
void shell(const char *prog)
{
    char str[STR_MAX];
    puts(prog);
    forever {
        printf("\n$ ");
        fflush(stdin);
        fgets(str,STR_MAX,stdin);
        str[strlen(str)-1] = '\0';
        trims(str,' ');
        trims(str,'\t');
        if(!strlen(str)) continue;
        if(!stricmp(str,"exit")) break;
        runs(str);
    }
}
Esempio n. 12
0
void shell(const char *prog)
{
	lex_cmd("hello hi  45.67 hoo 0x234 hee 67 !@#$%^&* ",0);
	lex_cmd("punch ( 423,  gfs,  sfds, 55664, BRR, %*@$@$ ) ",0);

	char str[STR_MAX];
	puts(prog);
	while(TRUE) {
		printf("\n$ ");
		fflush(stdin);
		fgets(str,STR_MAX,stdin);
		str[strlen(str)-1] = '\0';
		trims(str,' ');
		trims(str,'\t');
		if(!strlen(str)) continue;
		if(!stricmp(str,"exit")) break;
		runs(str);
	}
}
Esempio n. 13
0
void SkJSONCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
                                  const SkPaint& paint) {
    Json::Value command(Json::objectValue);
    command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTBLOB);
    Json::Value runs(Json::arrayValue);
    SkTextBlobRunIterator iter(blob);
    while (!iter.done()) {
        Json::Value run(Json::objectValue);
        Json::Value jsonPositions(Json::arrayValue);
        Json::Value jsonGlyphs(Json::arrayValue);
        const SkScalar* iterPositions = iter.pos();
        const uint16_t* iterGlyphs = iter.glyphs();
        for (uint32_t i = 0; i < iter.glyphCount(); i++) {
            switch (iter.positioning()) {
                case SkTextBlob::kFull_Positioning:
                    jsonPositions.append(this->makePoint(iterPositions[i * 2],
                                                         iterPositions[i * 2 + 1]));
                    break;
                case SkTextBlob::kHorizontal_Positioning:
                    jsonPositions.append(Json::Value(iterPositions[i]));
                    break;
                case SkTextBlob::kDefault_Positioning:
                    break;
            }
            jsonGlyphs.append(Json::Value(iterGlyphs[i]));
        }
        if (iter.positioning() != SkTextBlob::kDefault_Positioning) {
            run[SKJSONCANVAS_ATTRIBUTE_POSITIONS] = jsonPositions;
        }
        run[SKJSONCANVAS_ATTRIBUTE_GLYPHS] = jsonGlyphs;
        SkPaint fontPaint;
        iter.applyFontToPaint(&fontPaint);
        run[SKJSONCANVAS_ATTRIBUTE_FONT] = this->makePaint(fontPaint);
        run[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(iter.offset());
        runs.append(run);
        iter.next();
    }
    command[SKJSONCANVAS_ATTRIBUTE_RUNS] = runs;
    command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(x);
    command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(y);
    command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
    fCommands.append(command);
}
Esempio n. 14
0
int main(int   argc,
         char *argv[])
{
    qtimer_t t;

    assert(qthread_initialize() == QTHREAD_SUCCESS);

    CHECK_VERBOSE();

    t = qtimer_create();
    assert(t);
    qtimer_start(t);
    qtimer_stop(t);
    if (qtimer_secs(t) == 0) {
        fprintf(stderr, "qtimer_secs(t) reported zero length time.\n");
    } else if (qtimer_secs(t) < 0) {
        fprintf(stderr, "qtimer_secs(t) thinks time went backwards (%g).\n",
                qtimer_secs(t));
    }
    iprintf("time to find self and assert it: %g secs\n", qtimer_secs(t));

    qtimer_start(t);
    qtimer_stop(t);
    assert(qtimer_secs(t) >= 0.0);
    if (qtimer_secs(t) == 0.0) {
        iprintf("inlining reduces calltime to zero (apparently)\n");
    } else {
        iprintf("smallest measurable time: %g secs\n", qtimer_secs(t));
    }

    qtimer_destroy(t);

    // Now to test fastrand
    ks_test();
    runs();
    autocorrelation();

    qthread_finalize();

    return 0;
}
Esempio n. 15
0
int main(int argc, char *argv[])
{
	int32 *x = NULL;
	struct int32_list int32_my;
	init_int32(&int32_my);
	x = new_int32(&int32_my,34); if(x) *x = 111;
	x = new_int32(&int32_my,56); if(x) *x = 222;
	show_int32(&int32_my);puts("");
	x = get_int32(&int32_my,34);
	if(x) *x = 333;
	x = new_int32(&int32_my,78); if(x) *x = 555;
	del_int32(&int32_my,56);
	show_int32(&int32_my);puts("");
	free_int32(&int32_my);
	x = new_int32(&int32_my,10); *x = 999;
	show_int32(&int32_my);puts("");

	atexit(free_memory);
	/* program starts here */
	if(argc<=1) {
		/* there are no arguments, so run the shell */
		shell("LISP");
	} else {
		/* open each file (arg as filename) and run it. */
		FILE *afile=NULL;
		char str[1024];
		int32 i;
		for(i=1;i<argc;i++,afile=NULL) {
			if((afile = fopen(argv[i],"r"))!=NULL) {
			    while(fgets(str,1024,afile)!=NULL) {
					str[strlen(str)-1] = '\0';
					runs(str);
				} fclose(afile);
			} else
			printf("\nCould not open file: %s\n",argv[i]);
		}
	} return EXIT_SUCCESS;
}
// ---------------------------------------------------------------------------
// 
// -----------
void bToolTextEdition::clic(CGPoint pt, int count){
_bTrace_("bToolTextEdition::clic",true);
	bStdToolPres::clic(pt,count);
	
bArray*					ga;
bArray					runs(sizeof(bGenericXMLBaseElement*));
bGenericXMLBaseElement	*run,*gm,*elt;
bGenericGeoElement*		o=NULL;
int						i,n=_gapp->layersAccessCtx()->count();
CGPoint					p;
bGenericStyle*			_styl;
int						_fld;

	set_obj(NULL);
	get_clic(&p);
	for(i=n;i>0;i--){
		_styl=_gapp->layersAccessCtx()->get(i);
		if(!_styl){
			continue;
		}	
		ga=_styl->objsatpoint(&p,true);
		if(!ga){
			continue;
		}
		if(ga->count()<=0){
			delete ga;
			continue;
		}
		if(ga->count()>1){
			delete ga;
			break;
		}
		ga->get(1,&o);
		delete ga;
		break;
	}
	
	if(!o){
		_styl=NULL;
		return;
	}

bGenericUnit*	scl=_gapp->scaleMgr()->get();

	_styl->get_styleruns(runs,o,scl->coef(),1);

char			val[_values_length_max_];
bGenericType	*tp=_gapp->typesMgr()->get(o->getType());
	_fld=0;

	for(int i=1;i<=runs.count();i++){
		runs.get(i,&run);
		gm=_gapp->classMgr()->NthElement(run,1,"text");
		if(!gm){
			continue;
		}
		elt=_gapp->classMgr()->NthElement(gm,1,"field");
		if(!elt){
			continue;
		}
		elt->getvalue(val);
		_fld=tp->fields()->get_index(val);
		break;
	}

	if(!_fld){
_te_("no text field");
		_styl=NULL;
		return;
	}
	
	set_obj(o);

	o->getValue(_fld,val);
	if(GetAName(val,"",true)){
CGRect	bnds;
		_styl->rect(o,&bnds);
		_gapp->mapIntf()->inval(bnds);		
		
bEventLog	log(_gapp,
				getbundle(),
				kTextEditionMessageID,
				GetSignature(this));
		o->setValue(_fld,&val);	
		log.close();
		_styl->rect(o,&bnds);
		_gapp->mapIntf()->inval(bnds);		
	}
	
	set_obj(NULL);
}
Esempio n. 17
0
    /*
        check start and end of each contour
        if not the same, record them
        match them up
        connect closest
        reassemble contour pieces into new path
    */
void Assemble(const SkPathWriter& path, SkPathWriter* simple) {
#if DEBUG_PATH_CONSTRUCTION
    SkDebugf("%s\n", __FUNCTION__);
#endif
    SkTArray<SkOpContour> contours;
    SkOpEdgeBuilder builder(path, contours);
    builder.finish();
    int count = contours.count();
    int outer;
    SkTArray<int, true> runs(count);  // indices of partial contours
    for (outer = 0; outer < count; ++outer) {
        const SkOpContour& eContour = contours[outer];
        const SkPoint& eStart = eContour.start();
        const SkPoint& eEnd = eContour.end();
#if DEBUG_ASSEMBLE
        SkDebugf("%s contour", __FUNCTION__);
        if (!SkDPoint::ApproximatelyEqual(eStart, eEnd)) {
            SkDebugf("[%d]", runs.count());
        } else {
            SkDebugf("   ");
        }
        SkDebugf(" start=(%1.9g,%1.9g) end=(%1.9g,%1.9g)\n",
                eStart.fX, eStart.fY, eEnd.fX, eEnd.fY);
#endif
        if (SkDPoint::ApproximatelyEqual(eStart, eEnd)) {
            eContour.toPath(simple);
            continue;
        }
        runs.push_back(outer);
    }
    count = runs.count();
    if (count == 0) {
        return;
    }
    SkTArray<int, true> sLink, eLink;
    sLink.push_back_n(count);
    eLink.push_back_n(count);
    int rIndex, iIndex;
    for (rIndex = 0; rIndex < count; ++rIndex) {
        sLink[rIndex] = eLink[rIndex] = SK_MaxS32;
    }
    const int ends = count * 2;  // all starts and ends
    const int entries = (ends - 1) * count;  // folded triangle : n * (n - 1) / 2
    SkTArray<double, true> distances;
    distances.push_back_n(entries);
    for (rIndex = 0; rIndex < ends - 1; ++rIndex) {
        outer = runs[rIndex >> 1];
        const SkOpContour& oContour = contours[outer];
        const SkPoint& oPt = rIndex & 1 ? oContour.end() : oContour.start();
        const int row = rIndex < count - 1 ? rIndex * ends : (ends - rIndex - 2)
                * ends - rIndex - 1;
        for (iIndex = rIndex + 1; iIndex < ends; ++iIndex) {
            int inner = runs[iIndex >> 1];
            const SkOpContour& iContour = contours[inner];
            const SkPoint& iPt = iIndex & 1 ? iContour.end() : iContour.start();
            double dx = iPt.fX - oPt.fX;
            double dy = iPt.fY - oPt.fY;
            double dist = dx * dx + dy * dy;
            distances[row + iIndex] = dist;  // oStart distance from iStart
        }
    }
    SkTArray<int, true> sortedDist;
    sortedDist.push_back_n(entries);
    for (rIndex = 0; rIndex < entries; ++rIndex) {
        sortedDist[rIndex] = rIndex;
    }
    SkTQSort<int>(sortedDist.begin(), sortedDist.end() - 1, DistanceLessThan(distances.begin()));
    int remaining = count;  // number of start/end pairs
    for (rIndex = 0; rIndex < entries; ++rIndex) {
        int pair = sortedDist[rIndex];
        int row = pair / ends;
        int col = pair - row * ends;
        int thingOne = row < col ? row : ends - row - 2;
        int ndxOne = thingOne >> 1;
        bool endOne = thingOne & 1;
        int* linkOne = endOne ? eLink.begin() : sLink.begin();
        if (linkOne[ndxOne] != SK_MaxS32) {
            continue;
        }
        int thingTwo = row < col ? col : ends - row + col - 1;
        int ndxTwo = thingTwo >> 1;
        bool endTwo = thingTwo & 1;
        int* linkTwo = endTwo ? eLink.begin() : sLink.begin();
        if (linkTwo[ndxTwo] != SK_MaxS32) {
            continue;
        }
        SkASSERT(&linkOne[ndxOne] != &linkTwo[ndxTwo]);
        bool flip = endOne == endTwo;
        linkOne[ndxOne] = flip ? ~ndxTwo : ndxTwo;
        linkTwo[ndxTwo] = flip ? ~ndxOne : ndxOne;
        if (!--remaining) {
            break;
        }
    }
    SkASSERT(!remaining);
#if DEBUG_ASSEMBLE
    for (rIndex = 0; rIndex < count; ++rIndex) {
        int s = sLink[rIndex];
        int e = eLink[rIndex];
        SkDebugf("%s %c%d <- s%d - e%d -> %c%d\n", __FUNCTION__, s < 0 ? 's' : 'e',
                s < 0 ? ~s : s, rIndex, rIndex, e < 0 ? 'e' : 's', e < 0 ? ~e : e);
    }
#endif
    rIndex = 0;
    do {
        bool forward = true;
        bool first = true;
        int sIndex = sLink[rIndex];
        SkASSERT(sIndex != SK_MaxS32);
        sLink[rIndex] = SK_MaxS32;
        int eIndex;
        if (sIndex < 0) {
            eIndex = sLink[~sIndex];
            sLink[~sIndex] = SK_MaxS32;
        } else {
            eIndex = eLink[sIndex];
            eLink[sIndex] = SK_MaxS32;
        }
        SkASSERT(eIndex != SK_MaxS32);
#if DEBUG_ASSEMBLE
        SkDebugf("%s sIndex=%c%d eIndex=%c%d\n", __FUNCTION__, sIndex < 0 ? 's' : 'e',
                    sIndex < 0 ? ~sIndex : sIndex, eIndex < 0 ? 's' : 'e',
                    eIndex < 0 ? ~eIndex : eIndex);
#endif
        do {
            outer = runs[rIndex];
            const SkOpContour& contour = contours[outer];
            if (first) {
                first = false;
                const SkPoint* startPtr = &contour.start();
                simple->deferredMove(startPtr[0]);
            }
            if (forward) {
                contour.toPartialForward(simple);
            } else {
                contour.toPartialBackward(simple);
            }
#if DEBUG_ASSEMBLE
            SkDebugf("%s rIndex=%d eIndex=%s%d close=%d\n", __FUNCTION__, rIndex,
                eIndex < 0 ? "~" : "", eIndex < 0 ? ~eIndex : eIndex,
                sIndex == ((rIndex != eIndex) ^ forward ? eIndex : ~eIndex));
#endif
            if (sIndex == ((rIndex != eIndex) ^ forward ? eIndex : ~eIndex)) {
                simple->close();
                break;
            }
            if (forward) {
                eIndex = eLink[rIndex];
                SkASSERT(eIndex != SK_MaxS32);
                eLink[rIndex] = SK_MaxS32;
                if (eIndex >= 0) {
                    SkASSERT(sLink[eIndex] == rIndex);
                    sLink[eIndex] = SK_MaxS32;
                } else {
                    SkASSERT(eLink[~eIndex] == ~rIndex);
                    eLink[~eIndex] = SK_MaxS32;
                }
            } else {
                eIndex = sLink[rIndex];
                SkASSERT(eIndex != SK_MaxS32);
                sLink[rIndex] = SK_MaxS32;
                if (eIndex >= 0) {
                    SkASSERT(eLink[eIndex] == rIndex);
                    eLink[eIndex] = SK_MaxS32;
                } else {
                    SkASSERT(sLink[~eIndex] == ~rIndex);
                    sLink[~eIndex] = SK_MaxS32;
                }
            }
            rIndex = eIndex;
            if (rIndex < 0) {
                forward ^= 1;
                rIndex = ~rIndex;
            }
        } while (true);
        for (rIndex = 0; rIndex < count; ++rIndex) {
            if (sLink[rIndex] != SK_MaxS32) {
                break;
            }
        }
    } while (rIndex < count);
#if DEBUG_ASSEMBLE
    for (rIndex = 0; rIndex < count; ++rIndex) {
       SkASSERT(sLink[rIndex] == SK_MaxS32);
       SkASSERT(eLink[rIndex] == SK_MaxS32);
    }
#endif
}
Esempio n. 18
0
/* Score the hand */
score_t score(hand_t * hand) {
    return right_jack(hand) + runs(hand) 
        + pairs(hand) + fifteens(hand);
}
// ---------------------------------------------------------------------------
// 
// -----------
void bToolJustification::clic(CGPoint pt, int count){
_bTrace_("bToolJustification::clic",true);
	bStdToolPres::clic(pt,count);
	if(count>1){
		return;
	}
	
bArray*					ga;
bArray					runs(sizeof(bGenericXMLBaseElement*));
bGenericXMLBaseElement	*run,*gm,*elt;
bGenericGeoElement*		o=NULL;
int						i,n=_gapp->layersAccessCtx()->count();
CGPoint					p;
	
	set_obj(NULL);
	get_clic(&p);
	
	_fjust=0;
	_ijust=0;
	_fspc=0;
	_ispc=0;

	_styl=NULL;
	
	_curjust=0;
	_curspc=0;
	_pthlen=0;
	_txtwdt=0;
	_compjust=0;
	
	_xpts=NULL;
	_ypts=NULL;
	_offs=NULL;
	_npts=0;
	_noffs=0;
	
	for(i=n;i>0;i--){
		_styl=_gapp->layersAccessCtx()->get(i);
		if(!_styl){
			continue;
		}	
		ga=_styl->objsatpoint(&p,true);
		if(!ga){
			continue;
		}
		if(ga->count()<=0){
			delete ga;
			continue;
		}
		if(ga->count()>1){
			delete ga;
			break;
		}
		ga->get(1,&o);
		delete ga;
		break;
	}
	
	if(!o){
		_styl=NULL;
		return;
	}

bGenericUnit*	scl=_gapp->scaleMgr()->get();

	_styl->get_styleruns(runs,o,scl->coef(),1);

char			val[_values_length_max_];
bGenericType	*tp=_gapp->typesMgr()->get(o->getType());
	
	_jkd=kJustificationKindNone;

	for(int i=1;i<=runs.count();i++){
		runs.get(i,&run);
		_fjust=0;
		_fspc=0;
		gm=_gapp->classMgr()->NthElement(run,1,"polyjustification");
		if(!gm){
			gm=_gapp->classMgr()->NthElement(run,1,"pointjustification");
			if(!gm){
				continue;
			}
			_jkd=kJustificationKindOnPoint;
		}
		else{
			_jkd=kJustificationKindOnPath;
		}
		elt=_gapp->classMgr()->NthElement(gm,1,"field");
		if(!elt){
			continue;
		}
		elt->getvalue(val);
		_fjust=tp->fields()->get_index(val);
		
		if(_jmd==kJustificationMethodGlyphSpace){
			gm=_gapp->classMgr()->NthElement(run,1,"charspacing");
			elt=_gapp->classMgr()->NthElement(gm,1,"field");
			if(!elt){
				_fjust=0;
				continue;
			}
			elt->getvalue(val);
			_fspc=tp->fields()->get_index(val);
		}
		else if(_jmd==kJustificationKindOnWordSpace){
			gm=_gapp->classMgr()->NthElement(run,1,"wordspacing");		
			elt=_gapp->classMgr()->NthElement(gm,1,"field");
			if(!elt){
				_fspc=0;
				continue;
			}
			elt->getvalue(val);
			_fspc=tp->fields()->get_index(val);
		}
		break;
	}

	if(!_fjust){
		_styl=NULL;
_te_("no just field");
		return;
	}
	set_obj(o);

bGenericGraphicContext*	ctx=_styl->get_context_for_object(o,0,false);
bCoreTextInfo*			txt=ctx->getText();
float					*xpts,*ypts;
int						*offs;

	ctx->getGeometry(&xpts,&ypts,&_npts,&offs,&_noffs);
		
	if(	(_jkd==kJustificationKindOnPath)&&
		(_npts<2)						){
		ctx->setGeometry(NULL,NULL,0,NULL,0);
		_styl=NULL;
		_fjust=0;
		_fspc=0;
		_jmd=kJustificationKindNone;
		_umode=kJustificationUserModeStd;
		_jkd=kJustificationKindNone;
_te_("_npts<2");
		return;
	}
	if(	(_jkd==kJustificationKindOnPoint)&&
		(_npts==0)						){
		ctx->setGeometry(NULL,NULL,0,NULL,0);
		_styl=NULL;
		_fjust=0;
		_fspc=0;
		_jmd=kJustificationKindNone;
		_umode=kJustificationUserModeStd;
		_jkd=kJustificationKindNone;
_te_("_npts==0");
		return;
	}
	if(!xpts||!ypts){
		ctx->setGeometry(NULL,NULL,0,NULL,0);
		_styl=NULL;
		_fjust=0;
		_fspc=0;
		_jmd=kJustificationKindNone;
		_umode=kJustificationUserModeStd;
		_jkd=kJustificationKindNone;
_te_("(!_xpts||!_ypts)");
		return;
	}

	_xpts=new float[_npts];
	memmove(_xpts,xpts,_npts*sizeof(float));
	_ypts=new float[_npts];
	memmove(_ypts,ypts,_npts*sizeof(float));
	_offs=new int[_noffs];
	memmove(_offs,offs,_noffs*sizeof(int));

	ctx->setGeometry(NULL,NULL,0,NULL,0);

	_txtwdt=txt->textWidth();
	_pthlen=0;
	o->getValue(_fjust,&_ijust);
	if(_fspc){
		o->getValue(_fspc,&_ispc);
		_curspc=_ispc;
	}
	
CGPoint		cgp=pt;
	if(_jkd==kJustificationKindOnPath){		
float		r;
		for(int i=0;i<_npts-1;i++){
			_pthlen+=XYDist(_xpts[i],_ypts[i],_xpts[i+1],_ypts[i+1]);
		}
		XYProjOnPath(cgp.x,cgp.y,_xpts,_ypts,_npts,&cgp.x,&cgp.y,&_clkidx,&r);
		if((r>0)&&(r<1)){
			_xpts=(float*)realloc(_xpts,(_npts+1)*sizeof(float));
			_ypts=(float*)realloc(_ypts,(_npts+1)*sizeof(float));
			_npts++;
			memmove(&_xpts[_clkidx+1],&_xpts[_clkidx],_npts-_clkidx);
			memmove(&_ypts[_clkidx+1],&_ypts[_clkidx],_npts-_clkidx);
			_xpts[_clkidx]=cgp.x;
			_ypts[_clkidx]=cgp.y;
		}
		set_clic(&cgp);
		_curjust=get_justification_on_path(cgp);
		_compjust=_curjust-_ijust;
		_curjust=_ijust;
	}
	else if(_jkd==kJustificationKindOnPoint){
		_compjust=XYDist(_xpts[0],_ypts[0],cgp.x,cgp.y);
		_curjust=_ijust;
		_pthlen=rad2deg(ctx->getAngle());
	}
	
	set_use_drag(true);
	set_use_track(true);
}
Esempio n. 20
0
int Starter::Run(int& argc, char** argv,
    Poco::Util::AbstractConfiguration* config)
{

  // The CTK PluginFramework needs a QCoreApplication
  if (!qApp)
  {
    BERRY_FATAL << "No QCoreApplication instance found. You need to create one prior to calling Starter::Run()";
  }

  InternalPlatform* platform = InternalPlatform::GetInstance();

  int returnCode = 0;

  // startup the internal platform
  platform->Initialize(argc, argv, config);
  platform->Launch();

  bool consoleLog = platform->ConsoleLog();

  // run the application
  IExtensionPointService::Pointer service =
      platform->GetExtensionPointService();
  if (service == 0)
  {
    platform->GetLogger()->log(
        Poco::Message(
            "Starter",
            "The extension point service could not be retrieved. This usually indicates that the BlueBerry OSGi plug-in could not be loaded.",
            Poco::Message::PRIO_FATAL));
    std::unexpected();
    returnCode = 1;
  }
  else
  {
    IConfigurationElement::vector extensions(
        service->GetConfigurationElementsFor(Starter::XP_APPLICATIONS));
    IConfigurationElement::vector::iterator iter;

    for (iter = extensions.begin(); iter != extensions.end();)
    {
      if ((*iter)->GetName() != "application")
        iter = extensions.erase(iter);
      else
        ++iter;
    }

    std::string argApplication = Platform::GetConfiguration().getString(
        Platform::ARG_APPLICATION, "");

    IApplication* app = 0;
    if (extensions.size() == 0)
    {
      BERRY_FATAL
          << "No extensions configured into extension-point '" << Starter::XP_APPLICATIONS << "' found. Aborting.\n";
      returnCode = 0;
    }
    else if (extensions.size() == 1)
    {
      if (!argApplication.empty())
        BERRY_INFO(consoleLog)
            << "One '" << Starter::XP_APPLICATIONS << "' extension found, ignoring "
            << Platform::ARG_APPLICATION << " argument.\n";
      std::vector<IConfigurationElement::Pointer> runs(
          extensions[0]->GetChildren("run"));
      app = runs.front()->CreateExecutableExtension<IApplication> ("class");
      if (app == 0)
      {
        // support legacy BlueBerry extensions
        app = runs.front()->CreateExecutableExtension<IApplication> ("class", IApplication::GetManifestName());
      }
    }
    else
    {
      if (argApplication.empty())
      {
        BERRY_WARN << "You must provide an application id via \""
            << Platform::ARG_APPLICATION << "=<id>\"";
        BERRY_INFO << "Possible application ids are:";
        for (iter = extensions.begin(); iter != extensions.end(); ++iter)
        {
          std::string appid;
          if ((*iter)->GetAttribute("id", appid) && !appid.empty())
          {
            BERRY_INFO << appid;
          }
        }
        returnCode = 0;
      }
      else
      {
        for (iter = extensions.begin(); iter != extensions.end(); ++iter)
        {
          BERRY_INFO(consoleLog) << "Checking applications extension from: "
              << (*iter)->GetContributor() << std::endl;

          std::string appid;
          if ((*iter)->GetAttribute("id", appid))
          {
            BERRY_INFO(consoleLog) << "Found id: " << appid << std::endl;
            if (appid.size() > 0 && appid == argApplication)
            {
              std::vector<IConfigurationElement::Pointer> runs(
                  (*iter)->GetChildren("run"));
              app = runs.front()->CreateExecutableExtension<IApplication> ("class");
              if (app == 0)
              {
                // try legacy BlueBerry extensions
                app = runs.front()->CreateExecutableExtension<IApplication> (
                  "class", IApplication::GetManifestName());
              }
              break;
            }
          }
          else
            throw CoreException("missing attribute", "id");
        }
      }
    }

    if (app == 0)
    {
      BERRY_ERROR
          << "Could not create executable application extension for id: "
          << argApplication << std::endl;
      returnCode = 1;
    }
    else
    {
      returnCode = app->Start();
    }
  }

  platform->Shutdown();
  return returnCode;
}