static void fixup_text_block(fz_context *ctx, fz_text_block *block) { fz_text_line *line; fz_text_span *span; int i; /* cf. http://code.google.com/p/sumatrapdf/issues/detail?id=734 */ /* remove duplicate character sequences in (almost) the same spot */ for (line = block->lines; line < block->lines + block->len; line++) { for (span = line->spans; span < line->spans + line->len; span++) { if (span->style && span->style->size < 5) /* do_glyphs_overlap fails too often for small fonts */ continue; for (i = 0; i < span->len; i++) { fz_text_span *span2 = span; fz_text_line *line2 = line; int j = i + 1; for (; span2 <= line2->spans + line2->len; span2++, j = 0) { if (span2 == line2->spans + line2->len) { if (line2 + 1 == block->lines + block->len || line2 != line) break; span2 = (++line2)->spans; } for (; j < span2->len; j++) { int c = span->text[i].c; if (c != 32 && c == span2->text[j].c && do_glyphs_overlap(span, i, span2, j, 1)) goto fixup_delete_duplicates; } } continue; fixup_delete_duplicates: do { delete_character(span, i); if (span != span2) j++; } while (do_glyphs_overlap(span, i, span2, j, 0)); if (i < span->len && span->text[i].c == 32) delete_character(span, i); else if (i == span->len && span == line->spans + line->len - 1) { int len = line->len; merge_lines(ctx, block, line); span = line->spans + len - 1; } } } } }
void handle_delete_character( Network::Client* client, PKTIN_83* msg ) { u32 charidx = cfBEu32( msg->charidx ); if ( ( charidx >= Plib::systemstate.config.character_slots ) || ( client->acct == nullptr ) || ( client->acct->get_character( charidx ) == nullptr ) ) { send_login_error( client, LOGIN_ERROR_MISC ); client->Disconnect(); return; } Accounts::Account* acct = client->acct; Mobile::Character* chr = acct->get_character( charidx ); if ( chr->client != nullptr || ( !Plib::systemstate.config.allow_multi_clients_per_account && acct->has_active_characters() ) ) { send_login_error( client, LOGIN_ERROR_OTHER_CHAR_INUSE ); client->Disconnect(); return; } if ( can_delete_character( chr, DELETE_BY_PLAYER ) ) { call_ondelete_scripts( chr ); delete_character( acct, chr, charidx ); } send_start( client ); }
static void fixup_text_span(fz_text_span *span) { int i; for (i = 0; i < span->len; i++) { switch (span->text[i].c) { /* recombine characters and their accents */ case 0x00A8: /* diaeresis/umlaut */ case 0x00B4: /* accute accent */ case 0x0060: /* grave accent */ case 0x005E: case 0x02C6: /* circumflex accent */ case 0x02DA: /* ring above */ if (i + 1 < span->len) { int newC = 0; if (span->text[i + 1].c != 32 || i + 2 == span->len) newC = ornate_character(&span->text[i], &span->text[i + 1]); else if ((newC = ornate_character(&span->text[i], &span->text[i + 2]))) delete_character(span, i + 1); if (newC) { delete_character(span, i); span->text[i].c = newC; } } break; default: /* cf. http://code.google.com/p/sumatrapdf/issues/detail?id=733 */ /* reverse words written in RTL languages */ if (ISRIGHTTOLEFTCHAR(span->text[i].c)) { int j = i + 1; while (j < span->len && span->text[j - 1].bbox.x0 <= span->text[j].bbox.x0 && !ISLEFTTORIGHTCHAR(span->text[i].c)) j++; reverse_characters(span, i, j - 1); i = j; } } } }
void widget_text_keyhandler( input_key key ) { switch( key ) { case INPUT_KEY_BackSpace: /* Backspace generates DEL which is Caps + 0 */ delete_character(); widget_text_draw_text(); return; case INPUT_KEY_Escape: widget_end_widget( WIDGET_FINISHED_CANCEL ); return; case INPUT_KEY_Return: case INPUT_KEY_KP_Enter: widget_end_widget( WIDGET_FINISHED_OK ); return; default: /* Keep gcc happy */ break; } /* Input validation. * We rely on various INPUT_KEY_* being mapped directly onto ASCII. */ /* FIXME: we *don't* want keypresses filtered through the input layer */ /* First, return if the character isn't printable ASCII. */ if( key < ' ' || key > '~' ) return; /* Return if the key isn't valid. */ switch( allow ) { case WIDGET_INPUT_ASCII: break; case WIDGET_INPUT_DIGIT: if( !isdigit( key ) ) return; break; case WIDGET_INPUT_ALPHA: if( !isalpha( key ) ) return; break; case WIDGET_INPUT_ALNUM: if( !isdigit( key ) && !isalpha( key ) ) return; break; } /* If we've got this far, we have a valid key */ append_character( key ); widget_text_draw_text(); }
int delete_npc(Character *ch) { char buf[BUF_SIZ]; if (!delete_character(ch)) { return 0; } sprintf(buf, "delete from nonplayer where charId=%" PRId64, ch->id); if (sql_exec(buf) != SQL_OK) { log_data("could not delete player"); return 0; } return 1; }
/* Handler for control sequencie introducer, "ESC [" */ static void control_escape_csi(char ch) { switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': console->params[console->param_count] = 10 * console->params[console->param_count] + (ch - '0'); break; case ';': if (console->param_count + 1 == CONSOLE_MAX_PARAMS) log_error("Too many console parameters.\n"); else console->param_count++; break; case 'A': /* CUU */ move_up(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'B': /* CUD */ case 'e': /* VPR */ move_down(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'C': /* CUF */ case 'a': /* HPR */ move_right(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'D': /* CUB */ move_left(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'd': /* VPA */ { int y = console->params[0]? console->params[0]: 1; if (y > console->height) y = console->height; set_pos(console->x, y - 1); console->processor = NULL; break; } case 'G': /* CHA */ case '`': /* HPA */ { int x = console->params[0] ? console->params[0] : 1; if (x > console->width) x = console->width; set_pos(x - 1, console->y); console->processor = NULL; break; } case 'H': case 'f': /* Zero or one both represents the first row/column */ if (console->params[0] > 0) console->params[0]--; if (console->params[1] > 0) console->params[1]--; if (console->origin_mode) set_pos(console->params[1], console->scroll_top + console->params[0]); else set_pos(console->params[1], console->params[0]); console->processor = NULL; break; case 'h': if (console->private_mode) change_private_mode(console->params[0], 1); else change_mode(console->params[0], 1); console->processor = NULL; break; case 'J': erase_screen(console->params[0]); console->processor = NULL; break; case 'K': erase_line(console->params[0]); console->processor = NULL; break; case 'l': if (console->private_mode) change_private_mode(console->params[0], 0); else change_mode(console->params[0], 0); console->processor = NULL; break; case 'L': /* IL */ insert_line(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'M': /* DL */ delete_line(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case '@': /* ICH */ insert_character(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'P': /* DCH */ delete_character(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'm': for (int i = 0; i <= console->param_count; i++) { switch (console->params[i]) { case 0: /* Reset */ console->bright = 0; console->reverse = 0; console->foreground = 7; console->background = 0; break; case 1: console->bright = 1; break; case 2: console->bright = 0; break; case 7: console->reverse = 1; break; case 27: console->reverse = 0; break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: console->foreground = console->params[i] - 30; break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: console->background = console->params[i] - 40; break; default: log_error("Unknown console attribute: %d\n", console->params[i]); } } /* Set updated text attribute */ SetConsoleTextAttribute(console->out, get_text_attribute(console)); console->processor = NULL; break; case 'r': if (console->params[0] == 0) console->params[0] = 1; if (console->params[1] == 0) console->params[1] = console->height; console->scroll_full_screen = (console->params[0] == 1 && console->params[1] == console->height); console->scroll_top = console->params[0] - 1; console->scroll_bottom = console->params[1] - 1; set_pos(0, 0); console->processor = NULL; break; case 'S': /* SU */ scroll_up(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case '?': console->private_mode = 1; break; default: log_error("control_escape_csi(): Unhandled character %c\n", ch); console->processor = NULL; } }
void outputter(SCREEN_Screen* scr, int terminator, GetCharFunction getf) { while (1) { unsigned char c = getf(); if (c == terminator) { return; } switch (c) { case '\a': break; // TODO: alert? case '\t': tab(scr); break; case '\n': cursor_down(scr); break; case '\b': cursor_left(scr); break; case '\r': carriage_return(scr); break; case 0x1b: { c = getf(); switch (c) { case '[': { int x; if (getnum(getf, &x, &c)) { if (x == 1 && c == 'K') { clr_bol(scr); } else { switch (c) { case 'm': mode(scr, x); break; case 'A': parm_up_cursor(scr, x); break; case 'B': parm_down_cursor(scr, x); break; case 'C': parm_right_cursor(scr, x); break; case 'D': parm_left_cursor(scr, x); break; case 'G': column_address(scr, (x-1)); break; case 'L': parm_insert_line(scr, x); break; case 'M': parm_delete_line(scr, x); break; case 'P': parm_dch(scr, x); break; case 'S': parm_index(scr, x); break; case 'T': parm_rindex(scr, x); break; case 'X': erase_chars(scr, x); break; case '@': parm_ich(scr, x); break; case 'd': row_address(scr, (x-1)); break; case ';': { int y; if (getnum(getf, &y, &c)) { switch (c) { case 'm': mode(scr, x); mode(scr, y); break; case 'H': cursor_address(scr, mkpos(y-1, x-1)); break; default: fprintf(stderr, "unhandled: ESC[%i;%i%c\n", x, y, c); break; } } else { fprintf(stderr, "unhandled: ESC[%i;%c\n", x, c); } } break; default: fprintf(stderr, "unahndled: ESC[%i%c\n", x, c); break; } } } else { switch (c) { case '@': insert_character(scr); break; case 'A': cursor_up(scr); break; case 'B': cursor_down(scr); break; case 'C': cursor_right(scr); break; case 'D': cursor_left(scr); break; case 'H': cursor_home(scr); break; case 'I': tab(scr); break; case 'J': clr_eos(scr); break; case 'K': clr_eol(scr); break; case 'L': insert_line(scr); break; case 'M': delete_line(scr); break; case 'P': delete_character(scr); break; case 'm': exit_attribute_mode(scr); break; default: fprintf(stderr, "unhandled: ESC[%c\n", c); break; } } } break; case 'M': scroll_reverse(scr); break; default: fprintf(stderr, "unhandled: ESC%c\n", c); break; } } break; default: { wchar_t wc; if ((c & 0x80) == 0x00) { wc = c; } else if ((c & 0xE0) == 0xC0) { char c1 = 0x1F & c; char c2 = 0x3F & getf(); wc = (c1 << 6) | c2; } else if ((c & 0xF0) == 0xE0) { char c1 = 0x0F & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); wc = (c1 << 12) | (c2 << 6) | c3; } else if ((c & 0xF8) == 0xF0) { char c1 = 0x07 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); wc = (c1 << 18) | (c2 << 12) | (c3 << 6) | c4; } else if ((c & 0xFC) == 0xF8) { char c1 = 0x03 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); wc = (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | c5; } else if ((c & 0xFE) == 0xFC) { char c1 = 0x01 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); char c6 = 0x3F & getf(); wc = (c1 << 30) | (c2 << 24) | (c3 << 18) | (c4 << 12) | (c5 < 6) | c6; } else { fprintf(stderr, "bad utf-8 sequence: c=0x%02x\n", c); wc = '\0'; } put_char(scr, wc); } break; } } }