DWORD LStrList::SaveToFile(LTxtFile* tf, BOOL bIncludeNull) { DWORD ret = 0; LAutoLock al(m_lock); LIterator it = GetHeadIterator(); if (IsUnicode()) { while (NULL != it) { PCWSTR str = (PCWSTR)GetRawString(it); if (L'\0' != *str || bIncludeNull) { tf->WriteLn(str); ++ret; } it = GetNextIterator(it); } } else { while (NULL != it) { PCSTR str = (PCSTR)GetRawString(it); if ('\0' != *str || bIncludeNull) { tf->WriteLn(str); ++ret; } it = GetNextIterator(it); } } return ret; }
/* method: "get_text_raw(s)\nGet the unevaluated Text from Text objects." */ static utf8_string Shape_get_text_raw(const Object& self){ auto text = dynamic_cast<const ObjText*>(&self); if (!text){ throw ValueError(space_sep(self.GetType(), "does not support text.")); } return text->GetRawString(); }
static void Retrieve(BencDict *dict, const char *key, float& value) { const char *string = GetRawString(dict, key); if (string) { // note: this might round the value for files produced with versions // prior to 1.6 and on a system where the decimal mark isn't a '.' // (the difference should be hardly notable, though) value = (float)atof(string); } }
static void RetrieveRaw(BencDict *dict, const char *key, char *& value) { const char *string = GetRawString(dict, key); if (string) { char *str = str::Dup(string); if (str) { free(value); value = str; } } }
BOOL LStrList::IsEmptyLine(__in LIterator it) { PVOID pv = GetRawString(it); if (NULL == pv) return TRUE; if (IsUnicode()) return L'\0' == *((PCWSTR)pv); else return '\0' == *((PCSTR)pv); }
BOOL LStrList::GetAt(__in LIterator it, __out LStringW* str) { PVOID pv = GetRawString(it); if (NULL == pv) return FALSE; if (IsUnicode()) str->Copy((PCWSTR)pv); else str->Copy((PCSTR)pv); return TRUE; }
void CGUIString::GenerateTextCall(SFeedback &Feedback, CStrIntern DefaultFont, const int &from, const int &to, const bool FirstLine, const IGUIObject *pObject) const { // Reset width and height, because they will be determined with incrementation // or comparisons. Feedback.Reset(); // Check out which text chunk this is within. //bool match_found = false; std::vector<TextChunk>::const_iterator itTextChunk; for (itTextChunk=m_TextChunks.begin(); itTextChunk!=m_TextChunks.end(); ++itTextChunk) { // Get the area that is overlapped by both the TextChunk and // by the from/to inputted. int _from, _to; _from = std::max(from, itTextChunk->m_From); _to = std::min(to, itTextChunk->m_To); // If from is larger than to, than they are not overlapping if (_to == _from && itTextChunk->m_From == itTextChunk->m_To) { // These should never be able to have more than one tag. ENSURE(itTextChunk->m_Tags.size()==1); // Now do second check // because icons and images are placed on exactly one position // in the words-list, it can be counted twice if placed on an // edge. But there is always only one logical preference that // we want. This check filters the unwanted. // it's in the end of one word, and the icon // should really belong to the beginning of the next one if (_to == to && to >= 1) { if (GetRawString()[to-1] == ' ' || GetRawString()[to-1] == '-' || GetRawString()[to-1] == '\n') continue; } // This std::string is just a break if (_from == from && from >= 1) { if (GetRawString()[from] == '\n' && GetRawString()[from-1] != '\n' && GetRawString()[from-1] != ' ' && GetRawString()[from-1] != '-') continue; } // Single tags if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_IMGLEFT) { // Only add the image if the icon exists. if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { Feedback.m_Images[SFeedback::Left].push_back(itTextChunk->m_Tags[0].m_TagValue); } else if (pObject) { LOGERROR(L"Trying to use an [imgleft]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str()); } } else if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_IMGRIGHT) { // Only add the image if the icon exists. if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { Feedback.m_Images[SFeedback::Right].push_back(itTextChunk->m_Tags[0].m_TagValue); } else if (pObject) { LOGERROR(L"Trying to use an [imgright]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str()); } } else if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_ICON) { // Only add the image if the icon exists. if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { // We'll need to setup a text-call that will point // to the icon, this is to be able to iterate // through the text-calls without having to // complex the structure virtually for nothing more. SGUIText::STextCall TextCall; // Also add it to the sprites being rendered. SGUIText::SSpriteCall SpriteCall; // Get Icon from icon database in g_GUI SGUIIcon icon = g_GUI->GetIcon(itTextChunk->m_Tags[0].m_TagValue); CSize size = icon.m_Size; // append width, and make maximum height the height. Feedback.m_Size.cx += size.cx; Feedback.m_Size.cy = std::max(Feedback.m_Size.cy, size.cy); // These are also needed later TextCall.m_Size = size; SpriteCall.m_Area = size; // Handle additional attributes std::vector<TextChunk::Tag::TagAttribute>::const_iterator att_it; for(att_it = itTextChunk->m_Tags[0].m_TagAttributes.begin(); att_it != itTextChunk->m_Tags[0].m_TagAttributes.end(); ++att_it) { TextChunk::Tag::TagAttribute tagAttrib = (TextChunk::Tag::TagAttribute)(*att_it); if (tagAttrib.attrib == "displace" && !tagAttrib.value.empty()) { //Displace the sprite CSize displacement; // Parse the value if (!GUI<CSize>::ParseString(CStr(tagAttrib.value).FromUTF8(), displacement)) LOGERROR(L"Error parsing 'displace' value for tag [ICON]"); else SpriteCall.m_Area += displacement; } else if(tagAttrib.attrib == "tooltip") { SpriteCall.m_Tooltip = CStr(tagAttrib.value).FromUTF8(); } else if(tagAttrib.attrib == "tooltip_style") { SpriteCall.m_TooltipStyle = CStr(tagAttrib.value).FromUTF8(); } } SpriteCall.m_Sprite = icon.m_SpriteName; SpriteCall.m_CellID = icon.m_CellID; // Add sprite call Feedback.m_SpriteCalls.push_back(SpriteCall); // Finalize text call TextCall.m_pSpriteCall = &Feedback.m_SpriteCalls.back(); // Add text call Feedback.m_TextCalls.push_back(TextCall); } else if (pObject) { LOGERROR(L"Trying to use an [icon]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str()); } } } else if (_to > _from && !Feedback.m_NewLine) { SGUIText::STextCall TextCall; // Set defaults TextCall.m_Font = DefaultFont; TextCall.m_UseCustomColor = false; // Extract substd::string from RawString. TextCall.m_String = GetRawString().substr(_from, _to-_from); // Go through tags and apply changes. std::vector<CGUIString::TextChunk::Tag>::const_iterator it2; for (it2 = itTextChunk->m_Tags.begin(); it2 != itTextChunk->m_Tags.end(); ++it2) { if (it2->m_TagType == CGUIString::TextChunk::Tag::TAG_COLOR) { // Set custom color TextCall.m_UseCustomColor = true; // Try parsing the color std::string if (!GUI<CColor>::ParseString(CStr(it2->m_TagValue).FromUTF8(), TextCall.m_Color)) { if (pObject) LOGERROR(L"Error parsing the value of a [color]-tag in GUI text when reading object \"%hs\".", pObject->GetPresentableName().c_str()); } } else if (it2->m_TagType == CGUIString::TextChunk::Tag::TAG_FONT) { // TODO Gee: (2004-08-15) Check if Font exists? TextCall.m_Font = CStrIntern(it2->m_TagValue); } } // Calculate the size of the font CSize size; int cx, cy; CFontMetrics font (TextCall.m_Font); font.CalculateStringSize(TextCall.m_String.c_str(), cx, cy); // For anything other than the first line, the line spacing // needs to be considered rather than just the height of the text if (! FirstLine) cy = font.GetLineSpacing(); size.cx = (float)cx; size.cy = (float)cy; // Append width, and make maximum height the height. Feedback.m_Size.cx += size.cx; Feedback.m_Size.cy = std::max(Feedback.m_Size.cy, size.cy); // These are also needed later TextCall.m_Size = size; if (! TextCall.m_String.empty()) { if (TextCall.m_String[0] == '\n') { Feedback.m_NewLine = true; } } // Add text-chunk Feedback.m_TextCalls.push_back(TextCall); } } }
static void DeserializePrefs(const char *prefsTxt, SerializableGlobalPrefs& globalPrefs, FileHistory& fh, Favorites *favs) { BencObj *obj = BencObj::Decode(prefsTxt); if (!obj || obj->Type() != BT_DICT) goto Exit; BencDict *prefs = static_cast<BencDict *>(obj); BencDict *global = prefs->GetDict(GLOBAL_PREFS_STR); if (!global) goto Exit; Retrieve(global, TOOLBAR_VISIBLE_STR, globalPrefs.toolbarVisible); Retrieve(global, TOC_VISIBLE_STR, globalPrefs.tocVisible); Retrieve(global, FAV_VISIBLE_STR, globalPrefs.favVisible); Retrieve(global, SIDEBAR_DX_STR, globalPrefs.sidebarDx); Retrieve(global, TOC_DY_STR, globalPrefs.tocDy); Retrieve(global, PDF_ASSOCIATE_DONT_ASK_STR, globalPrefs.pdfAssociateDontAskAgain); Retrieve(global, PDF_ASSOCIATE_ASSOCIATE_STR, globalPrefs.pdfAssociateShouldAssociate); Retrieve(global, ESC_TO_EXIT_STR, globalPrefs.escToExit); Retrieve(global, USE_SYS_COLORS_STR, globalPrefs.useSysColors); Retrieve(global, BG_COLOR_STR, globalPrefs.bgColor); Retrieve(global, ENABLE_AUTO_UPDATE_STR, globalPrefs.enableAutoUpdate); Retrieve(global, REMEMBER_OPENED_FILES_STR, globalPrefs.rememberOpenedFiles); Retrieve(global, GLOBAL_PREFS_ONLY_STR, globalPrefs.globalPrefsOnly); Retrieve(global, SHOW_RECENT_FILES_STR, globalPrefs.showStartPage); Retrieve(global, DISPLAY_MODE_STR, globalPrefs.defaultDisplayMode); Retrieve(global, ZOOM_VIRTUAL_STR, globalPrefs.defaultZoom); Retrieve(global, WINDOW_STATE_STR, globalPrefs.windowState); Retrieve(global, WINDOW_X_STR, globalPrefs.windowPos.x); Retrieve(global, WINDOW_Y_STR, globalPrefs.windowPos.y); Retrieve(global, WINDOW_DX_STR, globalPrefs.windowPos.dx); Retrieve(global, WINDOW_DY_STR, globalPrefs.windowPos.dy); Retrieve(global, INVERSE_SEARCH_COMMANDLINE, globalPrefs.inverseSearchCmdLine); Retrieve(global, ENABLE_TEX_ENHANCEMENTS_STR, globalPrefs.enableTeXEnhancements); Retrieve(global, VERSION_TO_SKIP_STR, globalPrefs.versionToSkip); RetrieveRaw(global, LAST_UPDATE_STR, globalPrefs.lastUpdateTime); const char *lang = GetRawString(global, UI_LANGUAGE_STR); const char *langCode = trans::ValidateLanguageCode(lang); if (langCode) globalPrefs.currentLanguage = langCode; Retrieve(global, FWDSEARCH_OFFSET, globalPrefs.fwdSearch.offset); Retrieve(global, FWDSEARCH_COLOR, globalPrefs.fwdSearch.color); Retrieve(global, FWDSEARCH_WIDTH, globalPrefs.fwdSearch.width); Retrieve(global, FWDSEARCH_PERMANENT, globalPrefs.fwdSearch.permanent); Retrieve(global, CBX_RIGHT2LEFT, globalPrefs.cbxR2L); Retrieve(global, OPEN_COUNT_WEEK_STR, globalPrefs.openCountWeek); int weekDiff = GetWeekCount() - globalPrefs.openCountWeek; globalPrefs.openCountWeek = GetWeekCount(); BencArray *fileHistory = prefs->GetArray(FILE_HISTORY_STR); if (!fileHistory) goto Exit; size_t dlen = fileHistory->Length(); for (size_t i = 0; i < dlen; i++) { BencDict *dict = fileHistory->GetDict(i); assert(dict); if (!dict) continue; DisplayState *state = DeserializeDisplayState(dict, globalPrefs.globalPrefsOnly); if (state) { // "age" openCount statistics (cut in in half after every week) state->openCount >>= weekDiff; fh.Append(state); } } BencArray *favsArr = prefs->GetArray(FAVS_STR); if (!favsArr) goto Exit; for (size_t i = 0; i < favsArr->Length(); i += 2) { BencString *filePathBenc = favsArr->GetString(i); BencArray *favData = favsArr->GetArray(i+1); if (!filePathBenc || !favData) break; ScopedMem<WCHAR> filePath(filePathBenc->Value()); for (size_t j = 0; j < favData->Length(); j += 2) { // we're lenient about errors BencInt *pageNoBenc = favData->GetInt(j); BencString *nameBenc = favData->GetString(j + 1); if (!pageNoBenc || !nameBenc) break; int pageNo = (int)pageNoBenc->Value(); ScopedMem<WCHAR> name(nameBenc->Value()); favs->AddOrReplace(filePath, pageNo, EmptyToNull(name)); } } Exit: delete obj; }