void view_paint() { SDL_SetRenderDrawColor(g_renderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(g_renderer); render_char(digit1, 0); render_char(digit2, DIGIT_WIDTH); render_colon(colon); render_char(digit3, DIGIT_WIDTH * 2 + COLON_WIDTH); render_char(digit4, DIGIT_WIDTH * 2 + COLON_WIDTH + DIGIT_WIDTH); SDL_RenderPresent(g_renderer); }
/* render_gapbuf: renders an entire gap buffer */ void render_gapbuf (gapbuf G, WINDOW *w){ int i; for (i = 0 ; i < G->limit; i++) { // If G->buffer[i][1] != 0 , print G->buffer[i][0] // else print that highlighted if (G->buffer[i][1] == 0) { // if highlighted render_char(G->buffer[i][0], true, w); } else { render_char(G->buffer[i][1], false, w); } } }
static inline int waddch_literal(WINDOW *win, chtype ch) { int x; struct ldat *line; x = win->_curx; CHECK_POSITION(win, x, win->_cury); /* * If we're trying to add a character at the lower-right corner more * than once, fail. (Moving the cursor will clear the flag). */ if (win->_flags & _WRAPPED) { if (x >= win->_maxx) return (ERR); win->_flags &= ~_WRAPPED; } ch = render_char(win, ch); TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); line = win->_line+win->_cury; if (line->firstchar == _NOCHANGE) line->firstchar = line->lastchar = x; else if (x < line->firstchar) line->firstchar = x; else if (x > line->lastchar) line->lastchar = x; line->text[x++] = ch; TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); if (x > win->_maxx) { /* * The _WRAPPED flag is useful only for telling an application * that we've just wrapped the cursor. We don't do anything * with this flag except set it when wrapping, and clear it * whenever we move the cursor. If we try to wrap at the * lower-right corner of a window, we cannot move the cursor * (since that wouldn't be legal). So we return an error * (which is what SVr4 does). Unlike SVr4, we can successfully * add a character to the lower-right corner. */ win->_flags |= _WRAPPED; if (++win->_cury > win->_regbottom) { win->_cury = win->_regbottom; win->_curx = win->_maxx; if (!win->_scroll) return (ERR); scroll(win); } win->_curx = 0; return (OK); } win->_curx = x; return OK; }
static int centered_par_render_func(tex_par_t ppar, tex_buffer_t pbuf, int curline) { int wfirst = 0, wlast; int cfirst; tex_word_t curw; int curwidth; if (!ppar->u) return curline; while (wfirst < ppar->u) { // find the range of words to fit into one line if (ppar->words[wfirst]->u > pbuf->cols) { // the word is too long to fit into one line curw = ppar->words[wfirst]; cfirst = 0; while (cfirst + pbuf->cols - 1 < curw->u) { if (cfirst + pbuf->cols == curw->u) break; render_tex_char_ts(pbuf, curline, 0, &curw->chars[cfirst], pbuf->cols - 1); render_char(pbuf, curline, pbuf->cols - 1, '\\', 0, 0, 0, 0, 0); curline++; cfirst += pbuf->cols - 1; } render_tex_char_ts(pbuf, curline, 0, &curw->chars[cfirst], curw->u - cfirst); curline++; wfirst++; continue; } if (ppar->words[wfirst]->u == pbuf->cols) { // the word is exactly of line width curw = ppar->words[wfirst]; render_tex_char_ts(pbuf, curline, 0, curw->chars, curw->u); curline++; wfirst++; continue; } wlast = wfirst + 1; curwidth = ppar->words[wfirst]->u; while (wlast < ppar->u) { if (curwidth + ppar->words[wlast]->u + 1 > pbuf->cols) break; curwidth += ppar->words[wlast]->u + 1; wlast++; } wlast--; cfirst = (pbuf->cols - curwidth) / 2; while (wfirst <= wlast) { curw = ppar->words[wfirst]; render_tex_char_ts(pbuf, curline, cfirst, curw->chars, curw->u); cfirst += curw->u + 1; wfirst++; } curline++; } return curline; }
uint8_t mf_bwfont_render_character(const struct mf_font_s *font, int16_t x0, int16_t y0, uint16_t character, mf_pixel_callback_t callback, void *state) { const struct mf_bwfont_s *bwfont = (const struct mf_bwfont_s*)font; const struct mf_bwfont_char_range_s *range; uint16_t index; range = find_char_range(bwfont, character, &index); if (!range) return 0; return render_char(range, x0, y0, index, callback, state); }
// everything happens in this constructor. Ttt::Ttt(Writer* wr, std::string str, int unicode , std::string ttfont ) : my_writer(wr) { self = this; // so that static methods work.. int error; int linescale = 0; previous = false; // no previous char, for kerning previous_glyph_index = 0; // no index, for kerning error = FT_Init_FreeType(&library); if(error) handle_ft_error("FT_Init_FreeType" , error, __LINE__); error = FT_New_Face(library, ttfont.data() , 0, &face); if(error) handle_ft_error("FT_New_Face", error, __LINE__); #define MYFSIZE 64 error = FT_Set_Pixel_Sizes(face, 0, MYFSIZE); if (error) handle_ft_error("FT_Set_Pixel_Sizes", error, __LINE__); if (unicode) setlocale(LC_CTYPE, ""); // this redirects to the buffer cout_redirect redir( buffer.rdbuf() ); int l = str.length(); my_writer->preamble(); line_extents.reset(); long int offset = 0; const char* s = str.data(); while(*s ) { // loop through characters wchar_t wc; int r = mbtowc(&wc, s, l); // convert multibyte s, store in wc. return number of converted bytes if(r==-1) { s++; continue; } my_writer->start_glyph(s,wc, offset); // comment at start of glyph glyph_extents.reset(); offset += render_char(face, wc, offset, linescale); // the glyph line_extents.add_extents(glyph_extents); s += r; l -= r; my_writer->end_glyph(glyph_extents, advance); // comment at end of glyph } my_writer->set_extents(line_extents); my_writer->postamble(offset, line_extents); }
void render_string(char *fbp,int x,int y,char **font,char *string,unsigned short int effects){ unsigned long int counter = 0; unsigned long int offset = 0; int x_cur; int y_cur; x_cur = x; y_cur = y; for ( counter = 0; counter < strlen(string); counter++){ render_char(fbp,x_cur,y_cur,font,string[counter],effects); x_cur = x_cur + *font[0]; } }
static #if !USE_WIDEC_SUPPORT /* cannot be inline if it is recursive */ NCURSES_INLINE #endif int waddch_literal(WINDOW *win, NCURSES_CH_T ch) { int x; int y; struct ldat *line; x = win->_curx; y = win->_cury; CHECK_POSITION(win, x, y); ch = render_char(win, ch); line = win->_line + y; CHANGED_CELL(line, x); /* * Build up multibyte characters until we have a wide-character. */ if_WIDEC({ if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) { int len = _nc_build_wch(win, CHREF(ch)); if (len >= -1) { /* handle EILSEQ */ if (is8bits(CharOf(ch))) { const char *s = unctrl((chtype) CharOf(ch)); if (s[1] != 0) { return waddstr(win, s); } } if (len == -1) return waddch(win, ' '); } else { return OK; } } });
void font_draw(font_info* info, const char *text, float x, float y) { if (info == NULL || text == NULL) return; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, info->tex); glBindVertexArray(info->vao); glBindBuffer(GL_ARRAY_BUFFER, info->vbo); glEnableVertexAttribArray(info->attribute_coord); y += info->pointSize; // Bitmaps start at bottom-left corner. float aspect = 1.0; //min((float) glutGet(GLUT_WINDOW_WIDTH) / width, (float) glutGet(GLUT_WINDOW_HEIGHT) / height); float sx = aspect * (float)info->pixelsPerPoint / glutGet(GLUT_WINDOW_WIDTH);// float sy = aspect * (float)info->pixelsPerPoint / glutGet(GLUT_WINDOW_HEIGHT); x = -1 + x * sx; y = 1 - y * sy; float startX = x, startY = y; const char *p; for(p = text; *p; p++) render_char(info, *p, &x, &y, sx, sy, startX, startY); }
static int wadd_wch_literal(WINDOW *win, cchar_t ch) { int x; int y; struct ldat *line; x = win->_curx; y = win->_cury; CHECK_POSITION(win, x, y); ch = render_char(win, ch); line = win->_line + y; CHANGED_CELL(line, x); /* * Non-spacing characters are added to the current cell. * * Spacing characters that are wider than one column require some display * adjustments. */ { int len = wcwidth(CharOf(ch)); int i; int j; wchar_t *chars; if (len == 0) { /* non-spacing */ if ((x > 0 && y >= 0) || (win->_maxx >= 0 && win->_cury >= 1)) { if (x > 0 && y >= 0) chars = (win->_line[y].text[x - 1].chars); else chars = (win->_line[y - 1].text[win->_maxx].chars); for (i = 0; i < CCHARW_MAX; ++i) { if (chars[i] == 0) { TR(TRACE_VIRTPUT, ("added non-spacing %d: %x", x, (int) CharOf(ch))); chars[i] = CharOf(ch); break; } } } goto testwrapping; } else if (len > 1) { /* multi-column characters */ /* * Check if the character will fit on the current line. If it does * not fit, fill in the remainder of the line with blanks. and * move to the next line. */ if (len > win->_maxx + 1) { TR(TRACE_VIRTPUT, ("character will not fit")); return ERR; } else if (x + len > win->_maxx + 1) { int count = win->_maxx + 1 - x; TR(TRACE_VIRTPUT, ("fill %d remaining cells", count)); fill_cells(win, count); if (wrap_to_next_line(win) == ERR) return ERR; x = win->_curx; y = win->_cury; line = win->_line + y; } /* * Check for cells which are orphaned by adding this character, set * those to blanks. * * FIXME: this actually could fill j-i cells, more complicated to * setup though. */ for (i = 0; i < len; ++i) { if (isWidecBase(win->_line[y].text[x + i])) { break; } else if (isWidecExt(win->_line[y].text[x + i])) { for (j = i; x + j <= win->_maxx; ++j) { if (!isWidecExt(win->_line[y].text[x + j])) { TR(TRACE_VIRTPUT, ("fill %d orphan cells", j)); fill_cells(win, j); break; } } break; } } /* * Finally, add the cells for this character. */ for (i = 0; i < len; ++i) { cchar_t value = ch; SetWidecExt(value, i); TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)", i + 1, len, win->_begy + y, win->_begx + x)); line->text[x] = value; CHANGED_CELL(line, x); ++x; } goto testwrapping; } } /* * Single-column characters. */ line->text[x++] = ch; /* * This label is used only for wide-characters. */ testwrapping: TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s", (long) win->_cury, (long) win->_curx, x - 1, _tracech_t(CHREF(ch)))); if (x > win->_maxx) { return wrap_to_next_line(win); } win->_curx = (NCURSES_SIZE_T) x; return OK; }
_nc_render(WINDOW *win, NCURSES_CH_T ch) /* make render_char() visible while still allowing us to inline it below */ { return render_char(win, ch); }
static #if !USE_WIDEC_SUPPORT /* cannot be inline if it is recursive */ NCURSES_INLINE #endif int waddch_literal(WINDOW *win, NCURSES_CH_T ch) { int x; int y; struct ldat *line; x = win->_curx; y = win->_cury; CHECK_POSITION(win, x, y); ch = render_char(win, ch); line = win->_line + y; CHANGED_CELL(line, x); /* * Build up multibyte characters until we have a wide-character. */ #if NCURSES_SP_FUNCS #define DeriveSP() SCREEN *sp = _nc_screen_of(win); #else #define DeriveSP() /*nothing */ #endif if_WIDEC({ DeriveSP(); if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) { int len = _nc_build_wch(win, CHREF(ch)); if (len >= -1) { attr_t attr = AttrOf(ch); /* handle EILSEQ (i.e., when len >= -1) */ if (len == -1 && is8bits(CharOf(ch))) { int rc = OK; const char *s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) CharOf(ch)); if (s[1] != '\0') { while (*s != '\0') { rc = waddch(win, UChar(*s) | attr); if (rc != OK) break; ++s; } return rc; } } if (len == -1) return waddch(win, ' ' | attr); } else { return OK; } } });
/* Make render_char() visible while still allowing us to inline it below. */ NCURSES_CH_T _nc_render(WINDOW *win, NCURSES_CH_T ch) { return render_char(win, ch); }
gfx_pixmap_t *gfxr_draw_font(gfx_bitmap_font_t *font, const char *stext, int characters, PaletteEntry *fg0, PaletteEntry *fg1, PaletteEntry *bg) { unsigned char *text = (unsigned char *)stext; int height = font->height; int width = 0; gfx_pixmap_t *pxm; int fore_0, fore_1, back; int i; int hack = 0; PaletteEntry dummy(0,0,0); // black byte *offset; for (i = 0; i < characters; i++) { int ch = (int) text[i]; if (ch >= font->chars_nr) { error("Invalid character 0x%02x encountered", text[i]); return NULL; } width += font->widths[ch]; } pxm = gfx_pixmap_alloc_index_data(gfx_new_pixmap(width, height, GFX_RESID_NONE, 0, 0)); int colors_nr = !!fg0 + !!fg1 + !!bg; if (colors_nr == 0) { warning("[GFX] Pixmap would have zero colors, resetting"); colors_nr = 3; hack = 1; fg0 = fg1 = bg = &dummy; } pxm->palette = new Palette(colors_nr); pxm->palette->name = "font"; i = 0; if (fg0 || hack) { pxm->palette->setColor(i, fg0->r, fg0->g, fg0->b); fore_0 = i++; } else fore_0 = pxm->color_key; if (fg1 || hack) { pxm->palette->setColor(i, fg1->r, fg1->g, fg1->b); fore_1 = i++; } else fore_1 = pxm->color_key; if (bg || hack) { pxm->palette->setColor(i, bg->r, bg->g, bg->b); back = i++; } else back = pxm->color_key; offset = pxm->index_data; memset(pxm->index_data, back, pxm->index_width * pxm->index_height); for (i = 0; i < characters; i++) { unsigned char ch = text[i]; width = font->widths[ch]; render_char(offset, font->data + (ch * font->char_size), width, pxm->index_width, pxm->index_height, font->row_size, fore_0, fore_1, back); offset += width; } return pxm; }
static int justified_par_render_func(tex_par_t ppar, tex_buffer_t pbuf, int curline) { int indent, left_margin, right_margin, width, cur_left; int wfirst = 0, wlast, cfirst, ws, rems, i, curwidth; tex_word_t curw; if (!ppar->u) return curline; indent = ppar->indent; left_margin = ppar->left_margin; right_margin = ppar->right_margin; if (left_margin < 0) left_margin = 0; if (right_margin < 0) right_margin = 0; if (left_margin + 2 > pbuf->cols - right_margin) right_margin = 0; if (left_margin + 2 > pbuf->cols - right_margin) left_margin = 0; if (left_margin + indent < 0) indent = 0; if (left_margin + indent + 2 > pbuf->cols - right_margin) indent=left_margin; width = pbuf->cols - (left_margin + indent) - right_margin; cur_left = left_margin + indent; while (wfirst < ppar->u) { curw = ppar->words[wfirst]; if (curw->u > width) { cfirst = 0; render_tex_char_ts(pbuf, curline, cur_left, &curw->chars[cfirst], width - 1); render_char(pbuf, curline, left_margin + width - 1, '\\', 0, 0, 0, 0, 0); curline++; cfirst += width - 1; width = pbuf->cols - left_margin - right_margin; cur_left = left_margin; while (cfirst + width - 1 < curw->u) { if (cfirst + width == curw->u) break; render_tex_char_ts(pbuf, curline, cur_left, &curw->chars[cfirst], width - 1); render_char(pbuf, curline, left_margin + width - 1, '\\', 0, 0,0,0,0); curline++; cfirst += width - 1; } render_tex_char_ts(pbuf, curline, cur_left, &curw->chars[cfirst], curw->u - cfirst); curline++; wfirst++; } else if (curw->u == width) { render_tex_char_ts(pbuf, curline, cur_left, curw->chars, curw->u); width = pbuf->cols - left_margin - right_margin; cur_left = left_margin; curline++; wfirst++; } else { wlast = wfirst + 1; curwidth = ppar->words[wfirst]->u; while (wlast < ppar->u) { if (curwidth + ppar->words[wlast]->u + 1 > width) break; curwidth += ppar->words[wlast]->u + 1; wlast++; } wlast--; if (wlast + 1 == ppar->u) { cfirst = cur_left; while (wfirst <= wlast) { curw = ppar->words[wfirst]; render_tex_char_ts(pbuf, curline, cfirst, curw->chars, curw->u); cfirst += curw->u + 1; wfirst++; } curline++; return curline; } if (wfirst == wlast) { render_tex_char_ts(pbuf, curline, cur_left, curw->chars, curw->u); width = pbuf->cols - left_margin - right_margin; cur_left = left_margin; wfirst++; curline++; } else { cfirst = cur_left; rems = width; for (i = wfirst; i <= wlast; i++) rems -= ppar->words[i]->u; while (wfirst <= wlast) { curw = ppar->words[wfirst]; render_tex_char_ts(pbuf, curline, cfirst, curw->chars, curw->u); cfirst += curw->u; if (wfirst < wlast) { ws = rems / (wlast - wfirst); if ((rems % (wlast - wfirst))) ws++; cfirst += ws; rems -= ws; } wfirst++; } curline++; width = pbuf->cols - left_margin - right_margin; cur_left = left_margin; } } } return curline; }