static unsigned char * set_frame_custom2(unsigned char *frame, FrameDataNode const *node) { size_t const n = sizeOfNode(node); if (n > 10) { frame = set_4_byte_value(frame, node->fid); frame = set_4_byte_value(frame, (unsigned long) (n - 10)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* clear 1 encoding descriptor byte to indicate ISO-8859-1 format */ *frame++ = node->txt.enc == 1 ? 1 : 0; if (node->dsc.dim > 0) { if (node->dsc.enc != 1) { frame = writeChars(frame, node->dsc.ptr.l, node->dsc.dim); *frame++ = 0; } else { frame = writeUcs2s(frame, node->dsc.ptr.u, node->dsc.dim); *frame++ = 0; *frame++ = 0; } } if (node->txt.enc != 1) { frame = writeChars(frame, node->txt.ptr.l, node->txt.dim); } else { frame = writeUcs2s(frame, node->txt.ptr.u, node->txt.dim); } } return frame; }
static unsigned char * set_frame_comment(unsigned char *frame, FrameDataNode const *node) { size_t const n = sizeOfCommentNode(node); if (n > 10) { frame = set_4_byte_value(frame, node->fid); frame = set_4_byte_value(frame, (uint32_t) (n - 10)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* encoding descriptor byte */ *frame++ = node->txt.enc == 1 ? 1 : 0; /* 3 bytes language */ *frame++ = node->lng[0]; *frame++ = node->lng[1]; *frame++ = node->lng[2]; /* descriptor with zero byte(s) separator */ if (node->dsc.enc != 1) { frame = writeChars(frame, node->dsc.ptr.l, node->dsc.dim); *frame++ = 0; } else { frame = writeUcs2s(frame, node->dsc.ptr.u, node->dsc.dim); *frame++ = 0; *frame++ = 0; } /* comment full text */ if (node->txt.enc != 1) { frame = writeChars(frame, node->txt.ptr.l, node->txt.dim); } else { frame = writeUcs2s(frame, node->txt.ptr.u, node->txt.dim); } } return frame; }
/** * Adds a line of text to the dialog lines list */ void Dialog::addLine(const char *line, bool underlineP) { if ((_widthX > 0) || (_lineX > 0)) incLine(); int lineWidth = _vm->_font->current()->getWidth(line, DIALOG_SPACING); int lineLen = strlen(line); if ((lineWidth > _dialogWidth) || (lineLen >= _widthChars)) writeChars(line); else { _lines[_lines.size() - 1].xp = (_dialogWidth - 10 - lineWidth) / 2; strcpy(_lines[_lines.size() - 1].data, line); } if (underlineP) _lines[_lines.size() - 1].underline = true; incLine(); }
void writeResult(FILE *stream, wchar_t* unicodeStr) { int len = wcslen(unicodeStr); bool out = true; for (int i = 0; i < len; i++) { wchar_t curr = *(unicodeStr + i); if (out && curr != LEFT_TAG) { char* chars = convert2Chars(unicodeStr, i); writeChars(stream, chars); } else if (out && curr == LEFT_TAG) { out = false; } else if (!out && curr != RIGHT_TAG) { //<>之间的内容忽略 } else if (!out && curr == RIGHT_TAG) { out = true; } } }
Dialog::Dialog(MadsM4Engine *vm, const char *msgData, const char *title): View(vm, Common::Rect(0, 0, 0, 0)) { assert(msgData); _vm->_font->setFont(FONT_INTERFACE_MADS); const char *srcP = msgData; bool skipLine = false; bool initFlag = false; bool cmdFlag = false; bool crFlag = false; bool underline = false; _screenType = LAYER_DIALOG; _widthChars = 0; _dialogIndex = 0; _askPosition.x = 0; _askPosition.y = 0; _lineX = 0; _widthX = 0; _dialogWidth = 0; _commandCase = false; char dialogLine[256]; char cmdText[80]; char *lineP = &dialogLine[0]; char *cmdP = NULL; while (srcP && *(srcP - 1) != '\0') { if ((*srcP == '\n') || (*srcP == '\0')) { // Line completed *lineP = '\0'; ++srcP; if (!initFlag) { initDialog(); initFlag = true; } if (!skipLine) writeChars(dialogLine); else { addLine(dialogLine, underline); if (crFlag) incLine(); } // Clear the current line contents dialogLine[0] = '\0'; lineP = &dialogLine[0]; skipLine = crFlag = underline = false; continue; } else if (*srcP == '[') { // Start of a command sequence cmdFlag = true; cmdP = &cmdText[0]; ++srcP; continue; } else if (*srcP == ']') { // End of a command sequence *cmdP = '\0'; cmdFlag = false; strToUpper(cmdText); if (matchCommand(cmdText, "ASK")) { setupInputArea(); } else if (matchCommand(cmdText, "BAR")) { // Adds a full-width line instead of normal text addBarLine(); } else if (matchCommand(cmdText, "CENTER")) { // Center command skipLine = true; } else if (matchCommand(cmdText, "CR")) { // CR command if (skipLine) crFlag = true; else if (!initFlag) { initDialog(); initFlag = true; } } else if (matchCommand(cmdText, "NOUN1")) { // Noun command 1 handleNounSuffix(lineP, 1, cmdText + 5); } else if (matchCommand(cmdText, "NOUN2")) { // Noun command 2 handleNounSuffix(lineP, 2, cmdText + 5); } else if (matchCommand(cmdText, "SENTENCE")) { // Sentence command - loads the title into the line buffer strcpy(dialogLine, title); strToUpper(dialogLine); lineP += strlen(dialogLine) + 1; } else if (matchCommand(cmdText, "TAB")) { // Specifies the X offset for the current line _lines[_lines.size() - 1].xp = atoi(cmdText + 3); } else if (matchCommand(cmdText, "TITLE")) { // Title command - specifies the dialog width in number of characters skipLine = true; crFlag = true; underline = true; int id = atoi(cmdText + 5); if (id > 0) { // Suffix provided - specifies the dialog width in number of chars _widthChars = id * 2; _dialogWidth = id * (_vm->_font->current()->getMaxWidth() + DIALOG_SPACING) + 10; } } else if (matchCommand(cmdText, "UNDER")) { // Underline command underline = true; } else if (matchCommand(cmdText, "VERB")) { // Verb/vocab retrieval int verbId = 1; // TODO: Get correct vocab getVocab(verbId, &lineP); } else if (matchCommand(cmdText, "INDEX")) { // Index command _dialogIndex = atoi(cmdText + 5); } else { error("Unknown dialog command '%s' encountered", cmdText); } } *lineP++ = *srcP; if (cmdFlag) *cmdP++ = *srcP; ++srcP; } draw(); }
/** * 写入一个字符串 */ void ByteArray::writeString(const std::string &value) { writeNumber((int)value.size()); writeChars(value.c_str(), value.size(), 0); }
/** * 写入多个字节 */ void ByteArray::writeChars(const char *val) { writeChars(val, (int)strlen(val), 0); }
/** * 写入一个布尔值 */ void ByteArray::writeBOOL(bool value) { writeChars((char *)&value, 1, 0); }
/** * 写入一个字节 */ void ByteArray::writeByte(char value) { writeChars(&value, 1); }