Example #1
0
boolean ULabel::intersects (BoxObj& userb, Graphic* gs) {
    Transformer* t = gs->GetTransformer();
    PSFont* f = gs->GetFont();
    Coord xmax = f->Width(_string);
    Coord ymax = f->Height();
    Coord tx0, ty0, tx1, ty1;
    
    if (t != nil && t->Rotated()) {
	Coord x[4], tx[5];
	Coord y[4], ty[5];
    
	x[0] = x[3] = y[0] = y[1] = 0;
	x[2] = x[1] = xmax;
	y[2] = y[3] = ymax;
	transformList(x, y, 4, tx, ty, gs);
	tx[4] = tx[0];
	ty[4] = ty[0];
	FillPolygonObj fp (tx, ty, 5);
	return fp.Intersects(userb);
    
    } else if (t != nil) {
	t->Transform(0, 0, tx0, ty0);
	t->Transform(xmax, ymax, tx1, ty1);
	BoxObj b1 (tx0, ty0, tx1, ty1);
	return b1.Intersects(userb);

    } else {
	BoxObj b2 (0, 0, xmax, ymax);
	return b2.Intersects(userb);
    }
}
void StrBrowserGraphic::Natural (int& w, int& h) {
    FullGraphic gs;
    totalGS(gs);
    PSFont* font = gs.GetFont();
    w = _width - _width % font->Width("n");
    h = _height - _height % font->Height();
}
Example #3
0
void PostScriptView::ConstProcs (ostream& out) {
    UList* fonts = GetPSFonts();
    int nfonts = Count(fonts);

    out << "/IdrawDict " << (50 + nfonts) << " dict def\n";
    out << "IdrawDict begin\n\n";

    if (nfonts > 0) {
	for (const char** line = reencodeISO; *line != nil; ++line) {
	    out << *line << "\n";
	}

	for (UList* u = fonts->First(); u != fonts->End(); u = u->Next()) {
	    PSFont* font = GetFont(u);

	    // No way to check if the X font's encoding is iso8859-1, so...
	    if (strncmp(font->GetPrintFont(), "Symbol", 6) != 0) {
		out << "/" << font->GetPrintFont() << " reencodeISO def\n";
	    } else {
		out << "/" << font->GetPrintFont() << " dup findfont def\n";
	    }
	}
	out << "\n";
    }

    out << "/none null def\n";
    out << "/numGraphicParameters 17 def\n";
    out << "/stringLimit 65535 def\n\n";
}
Example #4
0
boolean TextGraphic::RotatedIntersects (BoxObj& userb, Graphic* gs) {
    int beg, end, lineSize, nextBeg, ypos = 0;
    const char* s = GetOriginal();
    int size = strlen(s);
    PSFont* f = gs->GetFont();
    Coord x[4], tx[5];
    Coord y[4], ty[5];
    
    x[0] = x[1] = x[2] = x[3] = y[0] = y[1] = 0;
    y[2] = y[3] = f->Height();

    for (beg = 0; beg < size; beg = nextBeg) {
        GetLine(s, size, beg, end, lineSize, nextBeg);
        x[1] = x[2] = f->Width(&s[beg], lineSize) - 1;
	transformList(x, y, 4, tx, ty, gs);
	tx[4] = tx[0];
	ty[4] = ty[0];
	FillPolygonObj fp(tx, ty, 5);
	if (fp.Intersects(userb)) {
            return true;
        }
        y[0] -= _lineHt;
        y[1] -= _lineHt;
        y[2] -= _lineHt;
        y[3] -= _lineHt;
    }
    return false;
}
Example #5
0
boolean ULabel::contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    PSFont* f = gs->GetFont();

    invTransform(pt._x, pt._y, gs);
    BoxObj b (0, 0, f->Width(_string), f->Height());
    return b.Contains(pt);
}
Example #6
0
Manipulator* TextOvView::CreateManipulator (
    Viewer* v, Event& e, Transformer* rel, Tool* tool
) {
    Manipulator* m = nil;
    Editor* ed = v->GetEditor();
    int tabWidth = Math::round(.5*ivinch);

    if (tool->IsA(GRAPHIC_COMP_TOOL)) {
        FontVar* fontVar = (FontVar*) ed->GetState("FontVar");
	ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar");
        PSFont* font = (fontVar == nil) ? psstdfont : fontVar->GetFont();
	PSColor* fg = (colVar == nil) ? psblack : colVar->GetFgColor();
        int lineHt = font->GetLineHt();

        Painter* painter = new Painter;
        painter->FillBg(false);
        painter->SetFont(font);
	painter->SetColors(fg, nil);
	Orientation o = v->GetOrientation();
	if (o!=Rotated) 
	  painter->SetTransformer(rel);
	else {
	  rel = new Transformer(rel);
	  rel->Rotate(90.0);
	  painter->SetTransformer(rel);
	  Unref(rel);
	}

        m = new TextManip(v, painter, lineHt, tabWidth, tool);

    } else if (tool->IsA(RESHAPE_TOOL)) {
        TextGraphic* textgr = (TextGraphic*) GetGraphic();
        Painter* painter = new Painter;
        int lineHt = textgr->GetLineHeight();
        Coord xpos, ypos;
        rel = new Transformer;
        const char* text = textgr->GetOriginal();
        int size = strlen(text);
        
        textgr->TotalTransformation(*rel);
        rel->Transform(0, 0, xpos, ypos);
        painter->FillBg(false);
        painter->SetFont(textgr->GetFont());
	painter->SetColors(textgr->GetFgColor(), nil);
        painter->SetTransformer(rel);
        Unref(rel);

        m = new TextManip(
            v, text, size, xpos, ypos, painter, lineHt, tabWidth, tool
        );

    } else {
        m = OverlayView::CreateManipulator(v, e, rel, tool);
    }
    return m;
}
Example #7
0
static boolean Uncollected (const char* name, UList* fonts) {
    for (UList* u = fonts->First(); u != fonts->End(); u = u->Next()) {
        PSFont* font = (PSFont*) (*u)();

        if (strcmp(font->GetPrintFont(), name) == 0) {
            return false;
        }
    }
    return true;
}
void StrBrowserGraphic::GetRowsCols (int& rows, int& cols) {
    FullGraphic gs;
    totalGS(gs);
    PSFont* font = gs.GetFont();

    rows = _height / font->Height();
    cols = _width / font->Width("n");

    rows = (rows == 0) ? 1 : rows;
    cols = (cols == 0) ? 1 : cols;
}
Example #9
0
static void CollectFonts (GraphicComp* comp, UList* fonts) {
    PSFont* font = comp->GetGraphic()->GetFont();

    if (font != nil && Uncollected(font->GetPrintFont(), fonts)) {
        fonts->Append(new UList(font));
    }

    Iterator i;

    for (comp->First(i); !comp->Done(i); comp->Next(i)) {
        CollectFonts(comp->GetComp(i), fonts);
    }
}
Example #10
0
void PostScriptView::Font (ostream& out) {
    PSFont* font = (PSFont*) GetGraphicComp()->GetGraphic()->GetFont();

    if (font == nil) {
	out << MARK << " f u\n";
    } else {
	const char* name = font->GetName();
	const char* pf = font->GetPrintFont();
	const char* ps = font->GetPrintSize();
	out << MARK << " f " << name << "\n";
	out << pf << " " << ps << " SetF\n";
    }
}
Example #11
0
void TextComp::Interpret (Command* cmd) {
    TextGraphic* gr = (TextGraphic*) GetGraphic();

    if (cmd->IsA(BRUSH_CMD) || cmd->IsA(PATTERN_CMD)) {
        // do nothing

    } else if (cmd->IsA(FONT_CMD)) {
        PSFont* font = ((FontCmd*) cmd)->GetFont();
        cmd->Store(this, new VoidData(gr->GetFont()));
        gr->SetFont(font);
        gr->SetLineHeight(font->Height());      // hack; should be state var
        Notify();

    } else {
        GraphicComp::Interpret(cmd);
    }
}
Example #12
0
boolean TextGraphic::UntransformedIntersects (BoxObj& userb, Graphic* gs) {
    int beg, end, lineSize, nextBeg, ypos = 0;
    const char* s = GetOriginal();
    int size = strlen(s);
    PSFont* f = gs->GetFont();
    BoxObj box(0, 0, 0, f->Height());

    for (beg = 0; beg < size; beg = nextBeg) {
        GetLine(s, size, beg, end, lineSize, nextBeg);
        box._right = f->Width(&s[beg], lineSize) - 1;
        if (box.Intersects(userb)) {
            return true;
        }
        box._top -= _lineHt;
        box._bottom -= _lineHt;
    }
    return false;
}
Example #13
0
void ULabel::getExtent (
    float& x0, float& y0, float& cx, float& cy, float& tol, Graphic* gs
) {
    PSFont* f = gs->GetFont();
    float width = f->Width(_string);
    float height = f->Height();

    if (gs->GetTransformer() == nil) {
	x0 = 0;
	y0 = 0;
	cx = width / 2;
	cy = height / 2;
    } else {
        transformRect(0, 0, width, height, x0, y0, cx, cy, gs);
	cx = (cx + x0)/2;
	cy = (cy + y0)/2;
    }
    tol = 0;
}
Example #14
0
TextOvComp::TextOvComp(istream& in, OverlayComp* parent) 
: OverlayComp(nil, parent) {
    _valid = GetParamList()->read_args(in, this); 

    /* correct font vertical position */
    PSFont* f = _gr->GetFont();
    float sep = 1 - (f ? f->GetLineHt() : 0);
    Transformer* t = _gr->GetTransformer();
    float dx = 0., dy = sep;

    if (t != nil) {
        float x0, y0, x1, y1;
        t->Transform(0., 0., x0, y0);
        t->Transform(0., sep, x1, y1);
        dx = x1 - x0;
        dy = y1 - y0;
    }
    _gr->Translate(dx, dy);
}
Example #15
0
void PostScriptView::FontNames (ostream& out) {
    UList* fonts = GetPSFonts();
    const char* comment = "%%DocumentFonts:";
    int linelen = strlen(comment);
    out << comment;

    for (UList* u = fonts->First(); u != fonts->End(); u = u->Next()) {
	PSFont* font = GetFont(u);

	if (linelen + strlen(font->GetPrintFont()) + 2 <= MAXLINELEN) {
	    out << " ";
	    ++linelen;
	} else {
	    out << "\n%%+ ";
	    linelen = strlen("%%+ ");
	}
	out << font->GetPrintFont();
	linelen += strlen(font->GetPrintFont());
    }
    out << "\n";
}
Example #16
0
boolean TextGraphic::contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    PSFont* f = gs->GetFont();
    BoxObj box(0, 0, 0, f->Height());
    int beg, end, lineSize, nextBeg, ypos = 0;
    const char* s = GetOriginal();
    int size = strlen(s);

    invTransform(pt._x, pt._y, gs);
    
    for (beg = 0; beg < size; beg = nextBeg) {
        GetLine(s, size, beg, end, lineSize, nextBeg);
        box._right = f->Width(&s[beg], lineSize) - 1;
        if (box.Contains(pt)) {
            return true;
        }
        box._top -= _lineHt;
        box._bottom -= _lineHt;
    }
    return false;
}
Example #17
0
boolean TextGraphic::TransformedIntersects (BoxObj& userb, Graphic* gs) {
    int beg, end, lineSize, nextBeg, ypos = 0;
    const char* s = GetOriginal();
    int size = strlen(s);
    PSFont* f = gs->GetFont();
    Coord l, b, r, t = f->Height();
    Coord tl, tb, tr, tt;

    l = b = r = 0;
    
    for (beg = 0; beg < size; beg = nextBeg) {
        GetLine(s, size, beg, end, lineSize, nextBeg);
        r = f->Width(&s[beg], lineSize) - 1;
	transform(l, b, tl, tb, gs);
        transform(r, t, tr, tt, gs);
        BoxObj box(tl, tb, tr, tt);
	if (box.Intersects(userb)) {
            return true;
        }
        b -= _lineHt;
        t -= _lineHt;
    }
    return false;
}
Example #18
0
void TextFileComp::Init() {

    /* read in the text from begstr to endstr */
    FILE* fptr = fopen(_pathname, "r");
    char *buffer;

    if (_linewidth == 0) {
	buffer = new char[1];
	buffer[0] = '\0';
	fclose (fptr);
	return;
    }
    if (!fptr) {
	buffer = new char[1];
	buffer[0] = '\0';
    } else {
	char inbuf[BUFSIZ];
        int nsub;
	buffer = new char[BUFSIZ];
	
	int bufsiz = BUFSIZ;
	int buflen = 0;

	fgets( inbuf, BUFSIZ, fptr);
	if (_begstr) 
	    while (!feof(fptr) && strncmp(_begstr, inbuf, strlen(_begstr)) != 0) 
		fgets( inbuf, BUFSIZ, fptr);

	int len;
	int nc = 0;
        int wordc = 0;
	char* wordbuf;
	char c;

	/* loop until eof or endstr is found */
	while (!feof(fptr) && (_endstr ? strncmp(_endstr, inbuf, strlen(_endstr)) != 0 : true)) {
	    len = strlen(inbuf);
            if (_linewidth > -1) 
	       nsub = len / _linewidth;
	    else 
	       nsub = 0;

	    /* double buffer length if needed */
	    if (buflen+len+nsub >= bufsiz) {
		bufsiz *= 2;
		char* newbuffer = new char[bufsiz];
		strcpy( newbuffer, buffer );
		delete buffer;
		buffer = newbuffer;
	    }

	    if (_linewidth > -1) {
		wordbuf = new char[len+nsub+1];

	        for (int i = 0; i < len; i++) {
	            c = inbuf[i];
		    ++nc;
		    if (c == ' ' || c == '\t' || c == '\n') {
			if (nc > _linewidth+1) {
			    strcpy(buffer+buflen, "\n");
	       		    ++buflen;
			    if (c == '\n' && nc > 1 ) {
			        wordbuf[wordc] = ' ';
			    } else {
			        wordbuf[wordc] = c;
                            }
			    wordbuf[wordc+1] = '\0';
			    nc = strlen(wordbuf);
			    wordc = 0;
			    strcpy(buffer+buflen, wordbuf);
	       		    buflen += strlen(wordbuf);
			
			} else {
			    if (c == '\n' && nc > 1 && i > 0) {
			        wordbuf[wordc] = ' ';
			        wordbuf[wordc+1] = '\0';
			    } else if (c == '\n' && i == 0) {
			        wordbuf[wordc] = c;
			        wordbuf[wordc+1] = c;
			        wordbuf[wordc+2] = '\0';
				nc = 0;
			    } else {
			        wordbuf[wordc] = c;
			        wordbuf[wordc+1] = '\0';
                            }
			    wordc = 0;
			    if (buffer[buflen-1] != ' ' || wordbuf[0] != ' ') {
				strcpy(buffer+buflen, wordbuf);
				buflen += strlen(wordbuf); 
			    } else {
				strcpy(buffer+buflen, wordbuf+1);
				buflen += strlen(wordbuf) - 1; 
			    }
			}
		    
		    } else {
			if (c=='\\') {
			    c = inbuf[++i];
			    if (isdigit(c)) {
				char buf[4];
				buf[0] = c; 
				buf[1] = buf[2] = buf[3] = '\0';
				if (isdigit(inbuf[i+1])) {
				    buf[1] = inbuf[++i];
				    if (isdigit(inbuf[i+1])) {
					buf[2] = inbuf[++i];
				    }
				}
				c = ParamList::octal(buf);
			    }
			} 
			wordbuf[wordc] = c;
			++wordc;
		    }
	        }
	        delete wordbuf;
	    
	    } else {
                strcpy(buffer+buflen, inbuf);
	        buflen += strlen(inbuf);
            }
	    fgets( inbuf, BUFSIZ, fptr);
	}
	/* done looping until eof or endstr is found */
    }

    fclose(fptr);

    /* setup the graphic */
    ((TextGraphic*)_gr)->SetOriginal(buffer);
    delete buffer;

    /* correct font vertical position */
    PSFont* f = _gr->GetFont();
    float sep = 1 - f->GetLineHt();
    Transformer* t = _gr->GetTransformer();
    float dx = 0., dy = sep;

    if (t != nil) {
        float x0, y0, x1, y1;
        t->Transform(0., 0., x0, y0);
        t->Transform(0., sep, x1, y1);
        dx = x1 - x0;
        dy = y1 - y0;
    }
    _gr->Translate(dx, dy);

}