/*! \brief Returns how much room is required to draw a string in the font. \param inText The string to be examined. \param fromOffset The offset in the string where to begin the examination. \param lenght The amount of bytes to be examined. \param inStyle The font. \return The space (in pixels) required to draw the given string. */ float WidthBuffer::StringWidth(const char *inText, int32 fromOffset, int32 length, const BFont *inStyle) { if (inText == NULL || length == 0) return 0; BAutolock _(fLock); int32 index = 0; if (!FindTable(inStyle, &index)) index = InsertTable(inStyle); char *text = NULL; int32 numChars = 0; int32 textLen = 0; char *sourceText = (char *)inText + fromOffset; const float fontSize = inStyle->Size(); float stringWidth = 0; for (int32 charLen = 0; sourceText < inText + length; sourceText += charLen) { charLen = UTF8NextCharLen(sourceText); // End of string, bail out if (charLen <= 0) break; // Some magic, to uniquely identify this charachter const uint32 value = CharToCode(sourceText, charLen); float escapement; if (GetEscapement(value, index, &escapement)) { // Well, we've got a match for this charachter stringWidth += escapement; } else { // Store this charachter into an array, which we'll // pass to HashEscapements() later int32 offset = textLen; textLen += charLen; numChars++; text = (char *)realloc(text, textLen); for (int32 x = 0; x < charLen; x++) text[offset + x] = sourceText[x]; } } if (text != NULL) { // We've found some charachters which aren't yet in the hash table. // Get their width via HashEscapements() stringWidth += HashEscapements(text, numChars, textLen, index, inStyle); free(text); } return stringWidth * fontSize; }
//功能读入窗口,中枢函数,返回false的时候读入结束 bool userDatabase::userRead(){ cout << endl << username << ">" << endl; switch(mySql.read()){ case 0: return false; case 1: if(!CreateTable()) cout << "[Error] Create table error!" << endl; break; case 2: if(!CreateView()) cout << "[Error] Create view error!" << endl; break; case 3: if(!CreateIndex()) cout << "[Error] Create index error!" << endl; break; case 10: if(!InsertTable()) cout << "[Error] Insert error!" << endl; break; case 11: if(!SelectTable()) cout << "[Error] Select error!" << endl; break; case 12: if(!DeleteTable()) cout << "[Error] Drop table error!" << endl; break; case 13: if(!UpdateTable()) cout << "[Error] Update table error!" << endl; break; case 14: if(!DeleteData()) cout << "[Error] Delete data error!" << endl; break; case 15: if(!DeleteView()) cout << "[Error] Delete view error!" << endl; break; case 16: if(!GrantToUser()) cout << "[Error] Grant to user error!" << endl; break; case 20: readme.createHelp(); break; case 21: readme.selectHelp(); break; case 22: readme.insertHelp(); break; case 23: readme.dropHelp(); break; case 24: readme.updateHelp(); break; case 25: InputAllTable(); InputAllView(); InputAllIndex(); break; case 26: InputAllTable(); break; case 27: InputAllView(); break; case 28: InputAllIndex(); break; default : printf("[Error] SQL input error!\n"); break; } return true; };