Exemplo n.º 1
0
TEST(TStr, LeftRight) {
	const TStr As = "aaabbbaaa";

	// basic tests
	EXPECT_EQ(As.Left(3), "aaa");
	EXPECT_EQ(As.Right(6), "aaa");

	// negative indexes
	EXPECT_EQ(As.Left(-6), "aaa");
	EXPECT_EQ(As.Right(-3), "aaa");

	// edge cases
	EXPECT_ANY_THROW(As.Left(1000));
	EXPECT_ANY_THROW(As.Right(1000));
	EXPECT_EQ(As.Right(0), "aaabbbaaa");
	EXPECT_EQ(As.Left(0), "");
}
Exemplo n.º 2
0
void TVizMapContext::PaintMgGlass(PGks Gks, const int& KeyWdFontSize) {
    // drawing the dark circle
    TFltRect ZoomRect = GetZoomRect();
    int SizeX = TFlt::Round((MgGlassSize/ZoomRect.GetXLen()) * Gks->GetWidth());
    int SizeY = TFlt::Round((MgGlassSize/ZoomRect.GetYLen()) * Gks->GetHeight());
    Gks->SetBrush(TGksBrush::New(ColorMgGlass));
    Gks->FillEllipse(ScreenX-SizeX, ScreenY-SizeY, ScreenX+SizeX, ScreenY+SizeY);
    // drawing the keywords
    if (MgGlassKeyWdV.Len() > 0) {
        // prepare the string
        Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize, TGksColor::GetBlack(), TFSet()|gfsBold));
        TStr KeyWdStr = Gks->BreakTxt(MgGlassKeyWdV, ", ", ",", MgGlassWindowWidth);       
        TStr NearPointStr;
        if (NearPointN != -1) {
            PVizMapPoint NearPoint = VizMapFrame->GetPoint(NearPointN);
            if (NearPoint->IsPointNm()) {
                TStr NearPointNm = NearPoint->GetPointNm();
                if (NearPointNm.IsStrIn("[[")) {
                    const int StartPos = NearPointNm.SearchStr("[[");
                    NearPointNm = NearPointNm.Left(StartPos - 1);
                }
                NearPointStr = Gks->BreakTxt(NearPointNm, 
                    " ", "", MgGlassWindowWidth, 1);
                NearPointStr.DelChAll('\n');
                NearPointStr += "\n";
            }
        }
        TStr DocCountStr = "#documents = " + MgGlassPoints.GetStr() + "\n";
        // compose the final message
        KeyWdStr = NearPointStr + DocCountStr + KeyWdStr;
        // find position of the window
        int WndWidth = Gks->GetTxtWidth(KeyWdStr) + 6;
        int WndHeight = Gks->GetTxtHeight(KeyWdStr) + 6;
        int PosX = ScreenX + 20, PosY = ScreenY + 20;
        if (PosX + WndWidth > Gks->GetWidth()) {
            PosX = ScreenX - 20 - WndWidth; }
        if (PosY + WndHeight > Gks->GetHeight()) {
            PosY = ScreenY - 20 - WndHeight; }
        // draw the keyword string
        Gks->SetBrush(TGksBrush::New(ColorMgGlassWndShadow));
        Gks->FillRect(PosX + 5, PosY + 5, 
            PosX + WndWidth + 5, PosY + WndHeight + 5);
        Gks->SetBrush(TGksBrush::New(ColorMgGlassWnd));
        Gks->SetPen(TGksPen::New(ColorMgGlassWndFrm));
        Gks->Rectangle(PosX, PosY, 
            PosX + WndWidth, PosY + WndHeight);
        Gks->PutTxt(KeyWdStr, PosX+3, PosY+3);
    }
}
Exemplo n.º 3
0
TFltRect TVizMapContext::PaintPointNm(PGks Gks, PVizMapPoint Point, const int& X, 
        const int& Y, const int& PointFontSize, const int& PointNmFontScale, 
        const bool& SelPointP, const bool& IsCatP) {

    // get and clean point name
    TStr PointNm = Point->GetPointNm(); 
    PointNm.ChangeChAll('_', ' ');
    if (PointNm.IsStrIn("[[")) {
        const int StartPos = PointNm.SearchStr("[[");
        PointNm = PointNm.Left(StartPos - 1);
    }
    // set font
    TGksColor FontColor = SelPointP ? ColorSelPointFont : ColorPointFont;
    const int FontSize = PointFontSize + TFlt::Round(Point->GetWgt()*PointNmFontScale);
    //TFSet FontStyle = IsCatP ? (TFSet() | gfsBold) : TFSet();
    //Gks->SetFont(TGksFont::New("ARIAL", FontSize, FontColor, FontStyle));
    Gks->SetFont(TGksFont::New("ARIAL", FontSize, FontColor));
    // refit it for the screen
    TStr ScreenPointNm = Gks->BreakTxt(PointNm, " ", "", PointNmWidth, PointNmMxLines);
    // calculate string position on the screen
    const int HalfTxtWidth = Gks->GetTxtWidth(ScreenPointNm) / 2;
    const int HalfTxtHeight = Gks->GetTxtHeight(ScreenPointNm) / 2;
     // draw it!
    const int MnX = X - HalfTxtWidth;
    int CurrY = Y - HalfTxtHeight;
    TStrV LineV; ScreenPointNm.SplitOnAllCh('\n', LineV);
    for (int LineN = 0; LineN < LineV.Len(); LineN++) {
        const int HalfLineWidth = Gks->GetTxtWidth(LineV[LineN]) / 2;
        const int LineHeight = Gks->GetTxtHeight(LineV[LineN]);
        Gks->PutTxt(LineV[LineN], MnX + (HalfTxtWidth - HalfLineWidth), CurrY);
        CurrY += LineHeight-3;
    }
    // finish
    return TFltRect(X - HalfTxtWidth, Y - HalfTxtHeight,
        X + HalfTxtWidth, Y + HalfTxtHeight - LineV.Len()*3);
}