Пример #1
0
int TextAscii::h(int width) const
{
    if(message.empty()) return 0;
    else
    if(0 == width || w() <= width) return CharHeight(font);

    int res = 0;
    int www = 0;
    
    std::string::const_iterator pos1 = message.begin();
    std::string::const_iterator pos2 = message.end();
    std::string::const_iterator space = pos2;

    while(pos1 < pos2)
    {
        if(std::isspace(*pos1)) space = pos1;

	if(www + CharWidth(*pos1, font) >= width)
	{
	    www = 0;
	    res += CharHeight(font);
	    if(pos2 != space) pos1 = space + 1;
	    space = pos2;
	    continue;
	}

        www += CharWidth(*pos1, font);
        ++pos1;
    }

    return res;
}
Пример #2
0
u16 TextUnicode::h(const u16 width) const
{
    if(message.empty()) return 0;
    else
    if(0 == width || w() <= width) return CharHeight(font);

    u16 res = 0;
    u16 www = 0;
    
    std::vector<u16>::const_iterator pos1 = message.begin();
    std::vector<u16>::const_iterator pos2 = message.end();
    std::vector<u16>::const_iterator space = pos2;

    while(pos1 < pos2)
    {
        if(isspace(*pos1)) space = pos1;

	if(www + CharWidth(*pos1, font) >= width)
	{
	    www = 0;
	    res += CharHeight(font);
	    if(pos2 != space) pos1 = space + 1;
	    space = pos2;
	    continue;
	}

        www += CharWidth(*pos1, font);
        ++pos1;
    }

    return res;
}
Пример #3
0
static void ellipsize (Str255 s, short width) {

	/*
	if the string fits inside the given number of pixels, fine -- do nothing
	and return.
	
	if not, return a string that does fit, with ellipses representing the 
	deleted characters.  ellipses are generated by pressing option-semicolon.
	*/
	
	char len;
	short newwidth;
	
	if ((newwidth = StringWidth (s)) <= width) /*nothing to do, the string fits*/
		return;
	
	len = s [0]; /* current length in characters*/
	
	width -= CharWidth ('É'); /* subtract width of ellipses*/
		
	do { /*until it fits (or we run out of characters)*/
	
		newwidth -= CharWidth (s [len]);
		
		--len;
	} while ((newwidth > width) && (len != 0));
	
	++len; /*make room for the ellipses*/
	
	s [len] = 'É'; 
	
	s [0] = (char) len;
	} /*ellipsize*/
unsigned glArchivItem_Font::getWidthInternal(const T_Iterator& begin, const T_Iterator& end, unsigned maxWidth, unsigned* maxNumChars) const
{
    unsigned curLineLen = 0, maxLineLen = 0;
    for(T_Iterator it = begin; it != end;)
    {
        const uint32_t curChar = GetNextCharAndIncIt<typename std::iterator_traits<T_Iterator>::value_type>()(it, end);
        if(curChar == '\n')
        {
            if(curLineLen > maxLineLen)
                maxLineLen = curLineLen;
            curLineLen = 0;
        } else
        {
            const unsigned cw = CharWidth(curChar);
            // If we limit the width and the current line will be longer, stop before it
            // Do not stop if this is the first char in this line
            if(T_limitWidth && curLineLen != 0 && curLineLen + cw > maxWidth)
            {
                MakePrevIt<T_Iterator>()(it, begin);
                *maxNumChars = static_cast<unsigned>(std::distance(begin, it));
                return curLineLen;
            }
            curLineLen += cw;
        }
    }

    if(T_limitWidth)
        *maxNumChars = static_cast<unsigned>(std::distance(begin, end));

    // Last line can be longest
    return std::max(curLineLen, maxLineLen);
}
Пример #5
0
void TextUnicode::Blit(u16 ax, u16 ay, const u16 maxw, Surface & dst)
{
    if(message.empty()) return;

    std::vector<u16>::const_iterator it = message.begin();
    std::vector<u16>::const_iterator it_end = message.end();
    const u16 sx = ax;

    for(; it != it_end; ++it)
    {
	if(maxw && (ax - sx) >= maxw) break;

	// end string
	if(0 == *it) continue;

	// space or unknown letter
	if(*it < 0x0021)
	{
	    ax += CharWidth(*it, font);
	    continue;
	}

	const Surface & sprite = AGG::GetUnicodeLetter(*it, font);
	if(!sprite.isValid()) return;

	sprite.Blit(ax, ay, dst);
	ax += sprite.w();
    }
}
static void
FindPosition(Widget w, XawTextPosition fromPos, int fromx, int width,
	     Bool stopAtWordBreak, XawTextPosition *resPos, int *resWidth,
	     int *resHeight)
{
    MultiSinkObject sink = (MultiSinkObject)w;
    TextWidget ctx = (TextWidget)XtParent(w);
    Widget source = ctx->text.source;
    XFontSet fontset = sink->multi_sink.fontset;
    XawTextPosition idx, pos, whiteSpacePosition = 0;
    int i, lastWidth, whiteSpaceWidth, rWidth;
    Boolean whiteSpaceSeen;
    wchar_t c;
    XFontSetExtents *ext = XExtentsOfFontSet(fontset);
    XawTextBlock blk;

    pos = XawTextSourceRead(source, fromPos, &blk, BUFSIZ);
    rWidth = lastWidth = whiteSpaceWidth = 0;
    whiteSpaceSeen = False;
    c = 0;

    for (i = 0, idx = fromPos; rWidth <= width; i++, idx++) {
	if (i >= blk.length) {
	    i = 0;
	    pos = XawTextSourceRead(source, pos, &blk, BUFSIZ);
	    if (blk.length == 0)
		break;
	}
	c = ((wchar_t *)blk.ptr)[i];
	lastWidth = rWidth;
	rWidth += CharWidth(sink, fontset, fromx + rWidth, c);

	if (c == _Xaw_atowc(XawLF)) {
	    idx++;
	    break;
	}
	else if ((c == _Xaw_atowc(XawSP) || c == _Xaw_atowc(XawTAB))
		 && rWidth <= width) {
	    whiteSpaceSeen = True;
	    whiteSpacePosition = idx;
	    whiteSpaceWidth = rWidth;
	}
    }

    if (rWidth > width && idx > fromPos) {
	idx--;
	rWidth = lastWidth;
	if (stopAtWordBreak && whiteSpaceSeen) {
	    idx = whiteSpacePosition + 1;
	    rWidth = whiteSpaceWidth;
	}
    }

    if (idx >= ctx->text.lastPos && c != _Xaw_atowc(XawLF))
	idx = ctx->text.lastPos + 1;

    *resPos = idx;
    *resWidth = rWidth;
    *resHeight = ext->max_logical_extent.height;
}
Пример #7
0
static HPDF_TextWidth
TextWidth  (HPDF_Font         font,
            const HPDF_BYTE  *text,
            HPDF_UINT         len)
{
    HPDF_FontAttr attr = (HPDF_FontAttr)font->attr;
    HPDF_TextWidth ret = {0, 0, 0, 0};
    HPDF_UINT i;
    HPDF_BYTE b = 0;

    HPDF_PTRACE ((" HPDF_TTFont_TextWidth\n"));

    if (attr->widths) {
        for (i = 0; i < len; i++) {
            b = text[i];
            ret.numchars++;
            ret.width += CharWidth (font, b);

            if (HPDF_IS_WHITE_SPACE(b)) {
                ret.numspace++;
                ret.numwords++;
            }
        }
    } else
        HPDF_SetError (font->error, HPDF_FONT_INVALID_WIDTHS_TABLE, 0);

    /* 2006.08.19 add. */
    if (HPDF_IS_WHITE_SPACE(b))
        ; /* do nothing. */
    else
        ret.numwords++;

    return ret;
}
Пример #8
0
/*
 * Given two positions, find the distance between them.
 */
static void
FindDistance(
		Widget w,
		XawTextPosition fromPos,	/* First position. */
		int fromx,	/* Horizontal location of first position. */
		XawTextPosition toPos,	/* Second position. */
		int *resWidth,	/* Distance between fromPos and resPos. */
		XawTextPosition * resPos,	/* Actual second position used. */
		int *resHeight)	/* Height required. */
{
    MultiSinkObject sink = (MultiSinkObject) w;
    Widget source = XawTextGetSource(XtParent(w));

    XawTextPosition inx, lastPos;
    wchar_t c;
    XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset);
    XawTextBlock blk;

    /* we may not need this */
    lastPos = GETLASTPOS;
    XawTextSourceRead(source, fromPos, &blk, (int) (toPos - fromPos));
    *resWidth = 0;
    for (inx = fromPos; inx != toPos && inx < lastPos; inx++) {
	if (inx - blk.firstPos >= blk.length)
	    XawTextSourceRead(source, inx, &blk, (int) (toPos - fromPos));
	c = ((wchar_t *) blk.ptr)[inx - blk.firstPos];
	*resWidth += CharWidth(w, fromx + *resWidth, c);
	if (c == _Xaw_atowc(XawLF)) {
	    inx++;
	    break;
	}
    }
    *resPos = inx;
    *resHeight = ext->max_logical_extent.height;
}
Пример #9
0
static void
FindPosition(
		Widget w,
		XawTextPosition fromPos,	/* Starting position. */
		int fromx,	/* Horizontal location of starting position. */
		int width,	/* Desired width. */
		Boolean stopAtWordBreak,	/* Whether the resulting
						   position should be at a word
						   break.  */
		XawTextPosition * resPos,	/* Resulting position. */
		int *resWidth,	/* Actual width used. */
		int *resHeight)	/* Height required. */
{
    MultiSinkObject sink = (MultiSinkObject) w;
    Widget source = XawTextGetSource(XtParent(w));

    XawTextPosition lastPos, inx, whiteSpacePosition = 0;
    int lastWidth = 0, whiteSpaceWidth = 0;
    Boolean whiteSpaceSeen;
    wchar_t c;
    XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset);
    XawTextBlock blk;

    lastPos = GETLASTPOS;

    XawTextSourceRead(source, fromPos, &blk, BUFSIZ);
    *resWidth = 0;
    whiteSpaceSeen = FALSE;
    c = 0;
    for (inx = fromPos; *resWidth <= width && inx < lastPos; inx++) {
	lastWidth = *resWidth;
	if (inx - blk.firstPos >= blk.length)
	    XawTextSourceRead(source, inx, &blk, BUFSIZ);
	c = ((wchar_t *) blk.ptr)[inx - blk.firstPos];
	*resWidth += CharWidth(w, fromx + *resWidth, c);

	if ((c == _Xaw_atowc(XawSP) || c == _Xaw_atowc(XawTAB)) &&
	    *resWidth <= width) {
	    whiteSpaceSeen = TRUE;
	    whiteSpacePosition = inx;
	    whiteSpaceWidth = *resWidth;
	}
	if (c == _Xaw_atowc(XawLF)) {
	    inx++;
	    break;
	}
    }
    if (*resWidth > width && inx > fromPos) {
	*resWidth = lastWidth;
	inx--;
	if (stopAtWordBreak && whiteSpaceSeen) {
	    inx = whiteSpacePosition + 1;
	    *resWidth = whiteSpaceWidth;
	}
    }
    if (inx == lastPos && c != _Xaw_atowc(XawLF))
	inx = lastPos + 1;
    *resPos = inx;
    *resHeight = ext->max_logical_extent.height;
}
Пример #10
0
void TextAscii::Blit(u16 ax, u16 ay, const u16 maxw, Surface & dst)
{
    if(message.empty()) return;

    std::string::const_iterator it = message.begin();
    std::string::const_iterator it_end = message.end();
    s8 oy = 0;
    const u16 sx = ax;

    for(; it != it_end; ++it)
    {
	if(maxw && (ax - sx) >= maxw) break;

	// space or unknown letter
	if(*it < 0x21)
	{
	    ax += CharWidth(*it, font);
	    continue;
	}

	const Surface & sprite = AGG::GetLetter(*it, font);
	if(!sprite.isValid()) return;

        // valign
	switch(*it)
	{
	    case '-':
    		oy = CharAscent(font) / 2;
    	    break;

	    case '_':
    		oy = CharAscent(font);
    	    break;

    	    // "
    	    case 0x22:
	    // '
    	    case 0x27:
        	oy = 0;
    	    break;

    	    case 'y':
    	    case 'g':
    	    case 'p':
    	    case 'q':
    	    case 'j':
        	oy = CharAscent(font) + CharDescent(font) - sprite.h();
    	    break;

    	    default:
        	oy = CharAscent(font) - sprite.h();
            break;
	}

	sprite.Blit(ax, ay + 2 + oy, dst);
	ax += sprite.w();
    }
}
/*
 * Function:
 *	GetCursorBounds
 *
 * Parameters:
 *	w    - text sink object
 *	rect - X rectangle to return the cursor bounds
 *
 * Description:
 *	Returns the size and location of the cursor.
 */
static void
GetCursorBounds(Widget w, XRectangle *rect)
{
    MultiSinkObject sink = (MultiSinkObject)w;

    rect->width = CharWidth(sink, sink->multi_sink.fontset, 0, _Xaw_atowc(XawSP));
    rect->height = (XExtentsOfFontSet(sink->multi_sink.fontset)
		    ->max_logical_extent.height);
    rect->x = sink->multi_sink.cursor_x;
    rect->y = sink->multi_sink.cursor_y - (short)rect->height;
}
Пример #12
0
f_unit_t CFontStyle::StringWidth(const char *s, int len) {
    f_unit_t r = 0;

    while (len > 0) {
        r += CharWidth(s);
        int cl = mcharlen(s);
        s += cl;
        len -= cl;
    }

    return r;
} /* CFontStyle::StringWidth */
Пример #13
0
u16 TextAscii::w(u16 s, u16 c) const
{
    if(message.empty()) return 0;

    u16 res = 0;

    if(s > message.size() - 1) s = message.size() - 1;
    if(!c || c > message.size()) c = message.size() - s;

    for(u16 ii = s; ii < s + c; ++ii)
	res += CharWidth(message[ii], font);

    return res;
}
Пример #14
0
static HPDF_UINT
MeasureText (HPDF_Font          font,
             const HPDF_BYTE   *text,
             HPDF_UINT          len,
             HPDF_REAL          width,
             HPDF_REAL          font_size,
             HPDF_REAL          char_space,
             HPDF_REAL          word_space,
             HPDF_BOOL          wordwrap,
             HPDF_REAL         *real_width)
{
    HPDF_DOUBLE w = 0;
    HPDF_UINT tmp_len = 0;
    HPDF_UINT i;

    HPDF_PTRACE ((" HPDF_TTFont_MeasureText\n"));

    for (i = 0; i < len; i++) {
        HPDF_BYTE b = text[i];

        if (HPDF_IS_WHITE_SPACE(b)) {
            tmp_len = i + 1;

            if (real_width)
                *real_width = (HPDF_REAL) w;

            w += word_space;
        } else if (!wordwrap) {
            tmp_len = i;

            if (real_width)
                *real_width = (HPDF_REAL) w;
        }

        w += (HPDF_DOUBLE)CharWidth (font, b) * font_size / 1000;

        /* 2006.08.04 break when it encountered  line feed */
        if (w > width || b == 0x0A)
            return tmp_len;

        if (i > 0)
            w += char_space;
    }

    /* all of text can be put in the specified width */
    if (real_width)
        *real_width = (HPDF_REAL) w;
    return len;
}
Пример #15
0
int TextUnicode::w(u32 s, u32 c) const
{
    u32 res = 0;
    u32 size = message.size();

    if(size)
    {
	if(s > size - 1) s = size - 1;
	if(!c || c > size) c = size - s;

	for(u32 ii = s; ii < s + c; ++ii)
	    res += CharWidth(message[ii], font);
    }

    return res;
}
Пример #16
0
void FormatFileName(HDC dc, const CString &fileName, CString &dottedFileName, int boxWidth)
{
  int stringWidth = StringWidth(fileName, dc);

  dottedFileName = fileName;

  // too small file name
  if( stringWidth < boxWidth ) return;

  // extract filename and path
  CString sPath = fileName;
  CString sFile = fileName;
  int i = sPath.ReverseFind('\\');
  if (i != -1)
  {
    sPath = sPath.Left(i);
    sFile.Delete(0, i);
  }
  else return; // nothing to format

  int pathWidth = StringWidth(sPath, dc);
  int fileWidth = stringWidth - pathWidth;
  if( fileWidth >= boxWidth )
  {
    dottedFileName = sFile;
    return; // too big file name
  }

  int dotsWidth = StringWidth(CString(L"...\\"), dc);
  int curWidth = dotsWidth;
  i = 0;
  while( (curWidth < (boxWidth - fileWidth)) && (i < sPath.GetLength()) )
  {
    curWidth += CharWidth(sPath[i++], dc);
  }
  if(curWidth >= boxWidth && i > 0)
    i--;

  sPath = sPath.Left(i);
  dottedFileName = sPath + L"..." + sFile;
}
Пример #17
0
/*****************************************************************************
 * BoxToChar(iChar)
 *
 * purpose: sets pixels in bitmap according to matBox(2-d array containing
 *          ready pixel info. on char being edited)
 *
 * params:  BYTE iChar : index of char in bitmap offset array(offsets)
 *
 * returns: none
 *
 * side effects: changes font bitmap
 *
 ****************************************************************************/
VOID
BoxToChar(
        BYTE iChar
        )
{
        DWORD x, y, offset;

    if (!fEdited)
        return;

    if (wBox != wBoxOld)                /* I.e if width has changed */
        CharWidth(iChar, wBox);         /* .. go fix it */

    offset = offsets[iChar];
    for (x = 0; x < wBox; x++)
        {
        for (y = 0; y < kBox; y++)
            SetPixel(hMemDC, offset + x, y,
                matBox[x] [y] == TRUE ? WHITE : BLACK);
        }
    fEdited = FALSE;
}
/*
 * Given two positions, find the distance between them
 */
static void
FindDistance(Widget w, XawTextPosition fromPos, int fromx,
	     XawTextPosition toPos, int *resWidth,
	     XawTextPosition *resPos, int *resHeight)
{
    MultiSinkObject sink = (MultiSinkObject)w;
    XFontSet fontset = sink->multi_sink.fontset;
    TextWidget ctx = (TextWidget)XtParent(w);
    Widget source = ctx->text.source;
    XawTextPosition idx, pos;
    wchar_t c;
    XFontSetExtents *ext = XExtentsOfFontSet(fontset);
    XawTextBlock blk;
    int i, rWidth;

    pos = XawTextSourceRead(source, fromPos, &blk, toPos - fromPos);
    rWidth = 0;
    for (i = 0, idx = fromPos; idx < toPos; i++, idx++) {
	if (i >= blk.length) {
	    i = 0;
	    XawTextSourceRead(source, pos, &blk, toPos - pos);
	    if (blk.length == 0)
		break;
	}
	c = ((wchar_t *)blk.ptr)[i];
	rWidth += CharWidth(sink, fontset, fromx + rWidth, c);
	if (c == _Xaw_atowc(XawLF)) {
	    idx++;
	    break;
	}
    }

    *resPos = idx;
    *resWidth = rWidth;
    *resHeight = ext->max_logical_extent.height;
}
/*
 * The following procedure manages the "insert" cursor
 */
static void
InsertCursor(Widget w, int x, int y, XawTextInsertState state)
{
    MultiSinkObject sink = (MultiSinkObject)w;
    XFontSet fontset = sink->multi_sink.fontset;
    Widget ctx = XtParent(w);
    XawTextPosition position = XawTextGetInsertionPoint(ctx);

    if (XtIsRealized(ctx)) {
	int fheight, fdiff;
	XawTextBlock block;
	wchar_t c;
	XawTextPosition selection_start, selection_end;
	Boolean has_selection;
	XFontSetExtents *ext = XExtentsOfFontSet(fontset);

	XawTextGetSelectionPos((Widget)ctx, &selection_start, &selection_end);
	has_selection = selection_start != selection_end;

	fheight = ext->max_logical_extent.height;
	fdiff = fheight - abs(ext->max_logical_extent.y);

	if ((sink->multi_sink.cursor_position != position || state == XawisOff)
	    && !has_selection && sink->multi_sink.laststate != XawisOff) {
	    wchar_t *ochar;

	    (void)XawTextSourceRead(XawTextGetSource(ctx),
				    sink->multi_sink.cursor_position,
				    &block, 1);
	    if (!block.length)
		ochar = NULL;
	    else {
		c = ((wchar_t *)block.ptr)[0];
		if (c == _Xaw_atowc(XawLF))
		    ochar = NULL;
		else if (c == _Xaw_atowc(XawTAB))
		    ochar = wspace;
		else
		    ochar = (wchar_t *)block.ptr;
	    }

	    if (!ochar)
		_XawTextSinkClearToBackground(w, sink->multi_sink.cursor_x,
					      (sink->multi_sink.cursor_y - 1 -
					      fheight), CharWidth(sink, fontset,
								  0, wspace[0]),
					      fheight);
	    else {
		if (XwcTextEscapement(sink->multi_sink.fontset, ochar, 1) != 0)
		    DisplayText(w, sink->multi_sink.cursor_x,
				sink->multi_sink.cursor_y - 1 - fheight,
				sink->multi_sink.cursor_position,
				sink->multi_sink.cursor_position + 1,
				False);
		else
		    PaintText(w, sink->multi_sink.normgc,
			      sink->multi_sink.cursor_x,
			      sink->multi_sink.cursor_y - 1 - fdiff,
			      ochar, 1,
			      ctx->core.background_pixmap != XtUnspecifiedPixmap);
	    }
	}

	if (!has_selection && state != XawisOff) {
	    wchar_t *nchar;
	    Boolean focus = ((TextWidget)ctx)->text.hasfocus;

	    (void)XawTextSourceRead(XawTextGetSource(ctx),
				    position, &block, 1);
	    c = ((wchar_t *)block.ptr)[0];
	    if (!block.length || c == _Xaw_atowc(XawLF)
		|| c == _Xaw_atowc(XawTAB))
		nchar = wspace;
	    else
		nchar = (wchar_t *)block.ptr;

	    if (focus) {
		if (XwcTextEscapement(sink->multi_sink.fontset, nchar, 1) != 0)
		    XwcDrawImageString(XtDisplay(ctx), XtWindow(ctx),
				       fontset, sink->multi_sink.invgc,
				       x, (y - 1 - fdiff), nchar, 1);
		else
		    DisplayText(w, x, y - 1 - fheight,
				position, position + 1, True);
	    }
	    else
		XDrawRectangle(XtDisplay(ctx), XtWindow(ctx),
			       sink->multi_sink.xorgc ?
			       sink->multi_sink.xorgc : sink->multi_sink.normgc,
			       x, y - 1 - fheight,
			       CharWidth(sink, fontset, 0, *nchar) - 1,
			       fheight - 1);
	  }
      }

    sink->multi_sink.cursor_x = x;
    sink->multi_sink.cursor_y = y;
    sink->multi_sink.laststate = state;
    sink->multi_sink.cursor_position = position;
}
Пример #20
0
/*
 * This function does not know about drawing more than one line of text.
 */
static void
DisplayText(
	       Widget w,
	       Position x,
	       Position y,
	       XawTextPosition pos1,
	       XawTextPosition pos2,
	       Boolean highlight)
{
    MultiSinkObject sink = (MultiSinkObject) w;
    Widget source = XawTextGetSource(XtParent(w));
    wchar_t buf[BUFSIZ];
    XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset);

    int j, k;
    XawTextBlock blk;
    GC gc = highlight ? sink->multi_sink.invgc : sink->multi_sink.normgc;
    GC invgc = highlight ? sink->multi_sink.normgc : sink->multi_sink.invgc;

    if (!sink->multi_sink.echo)
	return;

    y = (Position) (y + abs(ext->max_logical_extent.y));
    for (j = 0; pos1 < pos2;) {
	pos1 = (int) XawTextSourceRead(source, pos1, &blk, (int) (pos2 - pos1));
	for (k = 0; k < blk.length; k++) {
	    if (j >= BUFSIZ) {	/* buffer full, dump the text. */
		x = (Position) (x + PaintText(w, gc, x, y, buf, j));
		j = 0;
	    }
	    buf[j] = ((wchar_t *) blk.ptr)[k];
	    if (buf[j] == _Xaw_atowc(XawLF))
		continue;

	    else if (buf[j] == _Xaw_atowc(XawTAB)) {
		Position temp = 0;
		Dimension width;

		if ((j != 0)
		    && ((temp = (Position) PaintText(w, gc, x, y, buf, j)
			) == 0))
		    return;

		x = (Position) (x + temp);
		width = (Dimension) CharWidth(w, x, _Xaw_atowc(XawTAB));
		XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
			       invgc, (int) x,
			       (int) y - abs(ext->max_logical_extent.y),
			       (unsigned int) width,
			       (unsigned int) ext->max_logical_extent.height);
		x = (Position) (x + width);
		j = -1;
	    } else if (XwcTextEscapement(sink->multi_sink.fontset,
					 &buf[j], 1) == 0) {
		if (sink->multi_sink.display_nonprinting)
		    buf[j] = _Xaw_atowc('@');
		else
		    buf[j] = _Xaw_atowc(' ');
	    }
	    j++;
	}
    }
    if (j > 0)
	(void) PaintText(w, gc, x, y, buf, j);
}
Пример #21
0
/* This expects a cstring. Draws to the current port*/
void _draw_screen_text(
	char *text,
	screen_rectangle *destination,
	short flags,
	short font_id,
	short text_color)
{
	TextSpec old_font;
	short x, y;
	RGBColor old_color, new_color;
	char text_to_draw[256];

	assert(font_id>=0 && font_id<NUMBER_OF_INTERFACE_FONTS);
	
	GetFont(&old_font);
	SetFont(&interface_fonts.fonts[font_id]);

	GetForeColor(&old_color);
	_get_interface_color(text_color, &new_color);
	RGBForeColor(&new_color);

	/* Copy the text to draw.. */
	strcpy(text_to_draw, text);

	/* Check for wrapping, and if it occurs, be recursive... */
	if(flags & _wrap_text)
	{
/*еее WHAT IS THE INTERNATIONALIZED WAY OF DETERMINING NON-PRINTING CHARACTERS? IE SPACES? */
		short last_non_printing_character;
		short text_width;
		short count= 0;

		text_width= 0;
		last_non_printing_character= 0;
		count= 0;
		while(count<strlen(text_to_draw) && text_width<RECTANGLE_WIDTH(destination))
		{
			text_width+= CharWidth(text_to_draw[count]);
			if(text_to_draw[count]==' ') last_non_printing_character= count;
			count++;
		}
		
		if(count!=strlen(text_to_draw))
		{
			char remaining_text_to_draw[256];
			screen_rectangle new_destination;
			
			/* If we ever have to wrap text, we can't also center vertically.  Sorry */
			flags &= ~_center_vertical;
			flags |= _top_justified;
			
			/* Pass the rest of it back in, recursively, on the next line.. */
			BlockMove(&text_to_draw[last_non_printing_character+1], remaining_text_to_draw,
				strlen(&text_to_draw[last_non_printing_character+1])+1);
	
			new_destination= *destination;
			new_destination.top+= interface_fonts.line_spacing[font_id];
			_draw_screen_text(remaining_text_to_draw, &new_destination, flags, font_id, text_color);
	
			/* now truncate our text to draw...*/
			text_to_draw[last_non_printing_character]= 0;
		}
	}

	/* Handle the horizontal stuff. */
	if(flags & _center_horizontal || flags & _right_justified)
	{
		short text_width;
		
		text_width= TextWidth(text_to_draw, 0, strlen(text_to_draw));
		
		if(text_width>RECTANGLE_WIDTH(destination))
		{
			short length;
			short trunc_code;
	
			/* Truncate the puppy.. */	
			x= destination->left;
			length= strlen(text);
			trunc_code= TruncText(RECTANGLE_WIDTH(destination), text_to_draw, &length, truncEnd);
			text_to_draw[length]= 0;

			/* Now recenter it.. */
			text_width= TextWidth(text_to_draw, 0, strlen(text_to_draw));
			if (flags & _center_horizontal)
				x= destination->left+(((destination->right-destination->left)-text_width)>>1);
			else
Пример #22
0
void DrawCalendar()
{
 int i, j, k;
 char s[100];

	if (GetOrientation() == 0 || GetOrientation() == 3) {
		months_by_x = 3;
		months_by_y = 4;
		dx = cpar->dx_p;
		dy = cpar->dy_p;
		sx = cpar->sx_p;
		sy = cpar->sy_p;
		aw = cpar->aw;
		lh = cpar->lh;
	} else {
		months_by_x = 4;
		months_by_y = 3;
		dx = cpar->dx_l;
		dy = cpar->dy_l;
		sx = cpar->sx_l;
		sy = cpar->sy_l;
		aw = cpar->aw;
		lh = cpar->lh;
	}

 ClearScreen();
 //FillArea(0, 0, 600, 800, BLACK);
 //FillArea(10, 10, 580, 780, WHITE);
 SetFont(cal_title_font, BLACK);
 sprintf(s, "\x11    %d    \x12", year);
 DrawTextRect(0, 5, ScreenWidth(), 30, s, ALIGN_CENTER);
 HeaderWidth = StringWidth(s);
 SymbolWidth = CharWidth('A');

 for (i=0; i<months_by_y; i++)
 	for (j=0; j<months_by_x; j++)
 		{
		 int mn = i*months_by_x + j;
 		 SetFont(cal_month_font, BLACK);
 		 DrawTextRect(sx+dx*j, sy-(lh*3)/2+dy*i, dx, 1, GetLangText(MonthName[mn]), ALIGN_CENTER);
 		 SetFont(cal_day_font, BLACK);
 		 for (k=0; k<6; k++)
	 		DrawTextRect(sx+4+dx*j-(IsRTL() ? 10 : 0), sy+lh*k+dy*i, 50, 1, GetLangText(WeekName[k]), ALIGN_LEFT | RTLAUTO);
  		 SetFont(cal_day_font, DGRAY);
		 DrawTextRect(sx+4+dx*j-(IsRTL() ? 10 : 0), sy+lh*6+dy*i, 50, 1, GetLangText(WeekName[6]), ALIGN_LEFT | RTLAUTO);
	 	 for (k=1; k<43; k++)
	 	 	 if (calendar[mn][k]>0)
	 	 	 	{
	 	 		 if (k%7!=0) 
	 	 		 	SetFont(cal_date_font, BLACK);
	 	 		 	else
	 	 		 	SetFont(cal_date2_font, DGRAY);
 		 	 	 sprintf(s, "%d", calendar[mn][k]);
				 DrawTextRect(sx+(aw*8)/5+( (int) ((k-1)/7) )*aw+dx*j, sy+lh*((k-1)%7)+dy*i, aw, 1, s, ALIGN_CENTER);
				}
 		}
 if (year==CurDate->tm_year+1900)
 	{
 	 k=1;
 	 while (calendar[CurDate->tm_mon][k]!=CurDate->tm_mday) k++;
 	 InvertArea(sx+(aw*8)/5+1+( (int) ((k-1)/7) )*aw+dx*(CurDate->tm_mon%months_by_x), sy+lh*((k-1)%7)+dy*(CurDate->tm_mon/months_by_x), aw-2, lh-1);
 	 DrawRect(sx+(aw*8)/5+( (int) ((k-1)/7) )*aw+dx*(CurDate->tm_mon%months_by_x), sy+lh*((k-1)%7)+dy*(CurDate->tm_mon/months_by_x)+1, aw, lh-3, BLACK);
 	}
// SetFont(cour32, BLACK);
// sprintf(s, "%d %s %d", CurDate->tm_mday, GetLangText(MonthName[CurDate->tm_mon]), CurDate->tm_year+1900);
// DrawTextRect(50, 720, 500, 30, s, ALIGN_CENTER);
// DitherArea(0, 0, 600, 800, 4, 1);
 DrawPanel(NULL, CurrentDateStr(), NULL, -1);
 FullUpdate();
}
/**
 *  Gibt Infos, über die Unterbrechungspunkte in einem Text
 *
 *  @param[in]     text            Text, der auf Zeilen verteilt werden soll
 *  @param[in]     primary_width   Maximale Breite der ersten Zeile
 *  @param[in]     secondary_width Maximale Breite der weiteren Zeilen
 */
glArchivItem_Font::WrapInfo glArchivItem_Font::GetWrapInfo(const std::string& text, const unsigned short primary_width,
                                                           const unsigned short secondary_width)
{
    if(!fontNoOutline)
        initFont();

    RTTR_Assert(isValidUTF8(text)); // Can only handle UTF-8 strings!

    // Current line width
    unsigned line_width = 0;
    // Width of current word
    unsigned word_width = 0;
    unsigned curMaxLineWidth = primary_width;

    WrapInfo wi;
    // We start the first line at the first char (so wi.positions.size() == numLines)
    wi.positions.push_back(0);

    utf8Iterator it(text.begin(), text.begin(), text.end());
    utf8Iterator itEnd(text.end(), text.begin(), text.end());
    utf8Iterator itWordStart = it;

    const unsigned spaceWidth = CharWidth(' ');

    for(;; ++it)
    {
        uint32_t curChar = (it != itEnd) ? *it : 0;
        // Word ended
        if(curChar == 0 || curChar == '\n' || curChar == ' ')
        {
            // Is the current word to long for the current line
            if(word_width + line_width > curMaxLineWidth)
            {
                // Word does not fit -> Start new line

                // Can we fit the word in one line?
                if(word_width <= secondary_width)
                {
                    // New line starts at index of word start
                    wi.positions.push_back(static_cast<unsigned>(itWordStart.base() - text.begin()));
                    line_width = 0;
                } else
                {
                    // Word does not even fit on one line -> Put as many letters in one line as possible
                    for(utf8Iterator itWord = itWordStart; itWord != it; ++itWord)
                    {
                        unsigned letter_width = CharWidth(*itWord);

                        // Can we fit the letter onto current line?
                        if(line_width + letter_width <= curMaxLineWidth)
                            line_width += letter_width; // Add it
                        else
                        {
                            // Create new line at this letter
                            wi.positions.push_back(static_cast<unsigned>(itWord.base() - text.begin()));
                            line_width = letter_width;
                            itWordStart = nextIt(itWord);
                        }
                    }

                    // Restart word
                    word_width = 0;
                }
                curMaxLineWidth = secondary_width;
            }
            if(curChar == 0)
                break;
            else if(curChar == ' ')
            {
                // Set up this line if we are going to continue it (not at line break or text end)
                // Line contains word and whitespace
                line_width += word_width + spaceWidth;
                word_width = 0;
                itWordStart = nextIt(it);
            } else
            {
                // If line break add new line (after all the word-breaking above)
                itWordStart = nextIt(it);
                if(itWordStart == itEnd)
                    break; // Reached end
                word_width = 0;
                line_width = 0;
                wi.positions.push_back(static_cast<unsigned>(itWordStart.base() - text.begin()));
            }
        } else
        {
            // Some char -> Add its width
            word_width += CharWidth(curChar);
        }
    }

    // Ignore trailing newline
    if(wi.positions.back() + 1 >= text.length() && wi.positions.size() > 1)
        wi.positions.pop_back();
    return wi;
}
/*
 * This function does not know about drawing more than one line of text
 */
static void
DisplayText(Widget w, int x, int y,
	    XawTextPosition pos1, XawTextPosition pos2, Bool highlight)
{
    TextWidget ctx = (TextWidget)XtParent(w);
    MultiSinkObject sink = (MultiSinkObject)w;
    XFontSet fontset = sink->multi_sink.fontset;
    Widget source = XawTextGetSource(XtParent(w));
    wchar_t buf[256];
    XFontSetExtents *ext = XExtentsOfFontSet(fontset);
    int j, k;
    XawTextBlock blk;
    GC gc, invgc, tabgc;
    int max_x;
    Bool clear_bg;

    if (!sink->multi_sink.echo || !ctx->text.lt.lines)
	return;

    max_x = (int)XtWidth(ctx) - ctx->text.r_margin.right;
    clear_bg = !highlight && ctx->core.background_pixmap != XtUnspecifiedPixmap;

    gc = highlight ? sink->multi_sink.invgc : sink->multi_sink.normgc;
    invgc = highlight ? sink->multi_sink.normgc : sink->multi_sink.invgc;

    if (highlight && sink->multi_sink.xorgc)
	tabgc = sink->multi_sink.xorgc;
    else
	tabgc = invgc;

    y += abs(ext->max_logical_extent.y);
    for (j = 0; pos1 < pos2;) {
	pos1 = XawTextSourceRead(source, pos1, &blk, (int) pos2 - pos1);
	for (k = 0; k < blk.length; k++) {
	    if ((unsigned) j >= (sizeof(buf) / sizeof(wchar_t)) - 1) {
		/* buffer full, dump the text */
		if ((x += PaintText(w, gc, x, y, buf, j, clear_bg)) >= max_x)
		    return;
		j = 0;
	    }
	    buf[j] = ((wchar_t *)blk.ptr)[k];
	    if (buf[j] == _Xaw_atowc(XawLF))
		continue;

	    else if (buf[j] == _Xaw_atowc(XawTAB)) {
		unsigned int width;

		if (j != 0 &&
		    (x += PaintText(w, gc, x, y, buf, j, clear_bg)) >= max_x)
		    return;

		width = CharWidth(sink, fontset, x, _Xaw_atowc(XawTAB));
		if (clear_bg)
		    _XawTextSinkClearToBackground(w,
					x, y - abs(ext->max_logical_extent.y),
					width, ext->max_logical_extent.height);
		else
		    XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
				   tabgc, x,
				   y - abs(ext->max_logical_extent.y),
				   width,
				   ext->max_logical_extent.height);
		x += width;
		j = -1;
	    }
	    else if (XwcTextEscapement(sink->multi_sink.fontset, &buf[j], 1)
		     == 0) {
		if (sink->multi_sink.display_nonprinting)
		    buf[j] = _Xaw_atowc('@');
		else
		    buf[j] = _Xaw_atowc(XawSP);
	    }
	    j++;
	}
    }

    if (j > 0)
	(void)PaintText(w, gc, x, y, buf, j, clear_bg);
}