/** * Get a sprite reference from the \a rcd_file, retrieve the corresponding sprite, and put it in the \a spr destination. * @param rcd_file File to load from. * @param sprites Sprites already loaded from this file. * @param [out] spr Pointer to write the loaded sprite to. * @return Loading was successful. */ bool LoadSpriteFromFile(RcdFileReader *rcd_file, const ImageMap &sprites, ImageData **spr) { uint32 val = rcd_file->GetUInt32(); if (val == 0) { *spr = nullptr; return true; } const auto iter = sprites.find(val); if (iter == sprites.end()) return false; *spr = iter->second; return true; }
void ImageLoader::load_library(Atom name, const std::string& filename) { ImageMap images; if (has_extension(filename, ".ilb")) { BOOST_LOG_TRIVIAL(info) << "Loading image library: " << filename; load_ilb(filename, graphics, images); } else if (has_extension(filename, ".hss")) { BOOST_LOG_TRIVIAL(info) << "Loading image library: " << filename; load_hss(filename, graphics, images); } else { BOOST_LOG_TRIVIAL(warning) << "Don't know how to load image library: " << filename; } ImageLibraryResource *lib = resources->image_libraries[name].get(); for (auto iter = images.begin(); iter != images.end(); iter++) { Image *image = iter->second; lib->images[image->id].reset(image); } lib->loaded = true; }
int ShellBrowserChild::get_entry_image(ShellEntry* entry, LPCITEMIDLIST pidl, int shgfi_flags, ImageMap& cache) { SHFILEINFO sfi; int idx = -1; ImageMap::const_iterator found = cache.find(entry); if (found != cache.end()) return found->second; if (SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(sfi), shgfi_flags|SHGFI_PIDL|SHGFI_ICON|SHGFI_ADDOVERLAYS)) { idx = ImageList_AddIcon(_himl, sfi.hIcon); DestroyIcon(sfi.hIcon); } cache[entry] = idx; return idx; }
int GetImageIndex(const wxString &fileName) { int imageInd = -1; wxString fileExt = fileName.AfterLast(wxChar('.')); #ifdef _WIN32 // Special case for windows executables, icon and cursor files. if (fileExt.CmpNoCase(wxT("exe")) == 0 || fileExt.CmpNoCase(wxT("ico")) == 0 || fileExt.CmpNoCase(wxT("cur")) == 0) { // Do we already have an icon for the file? ImageMap::iterator it = g_imageMap.find(fileName); if (it != g_imageMap.end()) { // Use exsiting icon. imageInd = it->second; } else { wxString fullname = fileName; if (fileExt.CmpNoCase(wxT("exe")) == 0) fullname += wxT(";0"); // Icon index. // Try to load 16x16 icon. Load any icon if fails. wxIcon icon; if (!icon.LoadFile(fullname, wxBITMAP_TYPE_ICO, 16, 16)) icon.LoadFile(fullname, wxBITMAP_TYPE_ICO); // Add the icon into the list. if (icon.Ok()) { if (fileExt.CmpNoCase(wxT("cur")) != 0) { // Convert to bitmap. It fixes the alpha problem. wxBitmap bmp(icon); if (bmp.Ok()) imageInd = g_imageList->Add(bmp); } else { // Can't convert cursor to bitmap. imageInd = g_imageList->Add(icon); } } if (imageInd >= 0) g_imageMap.insert(ImagePair(fileName, imageInd)); } } #endif // _WIN32 if (imageInd < 0 && fileExt.Length() > 0) { // Do we already have an icon for the file type? ImageMap::iterator it = g_imageMap.find(fileExt); if (it != g_imageMap.end()) { // Use exsiting icon. imageInd = it->second; } else { // Ask mime types manager for the file type. // TODO: For some types (sdf, sln) it returns wrong index for the icon. Fix it. // TODO: For some types (doc, html) it returns invalid file name for the icon. Fix it. wxFileType *fileType = wxTheMimeTypesManager->GetFileTypeFromExtension(fileExt); if (fileType != NULL) { // Get icon location. wxIconLocation iconLoc; if (fileType->GetIcon(&iconLoc)) { wxString fullname = iconLoc.GetFileName(); #ifdef _WIN32 if (iconLoc.GetIndex()) fullname << wxT(';') << iconLoc.GetIndex(); #endif // Try to load 16x16 icon. Load any icon if fails. wxIcon icon; if (!icon.LoadFile(fullname, wxBITMAP_TYPE_ICO, 16, 16)) icon.LoadFile(fullname, wxBITMAP_TYPE_ICO); // Add the icon into the list. if (icon.Ok()) { // Convert to bitmap. It fixes the alpha problem. wxBitmap bmp(icon); if (bmp.Ok()) imageInd = g_imageList->Add(bmp); } if (imageInd >= 0) g_imageMap.insert(ImagePair(fileExt, imageInd)); } delete fileType; } } } // If no image found. if (imageInd < 0) { // Set default image. g_imageMap.insert(ImagePair(fileExt, kUnknownFileImage)); imageInd = kUnknownFileImage; } return imageInd; }
void SymbolLayout::prepare(const GlyphMap& glyphMap, const GlyphPositions& glyphPositions, const ImageMap& imageMap, const ImagePositions& imagePositions, const OverscaledTileID& tileID, const std::string& sourceID) { const bool textAlongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map && layout.get<SymbolPlacement>() == SymbolPlacementType::Line; auto glyphMapIt = glyphMap.find(layout.get<TextFont>()); const Glyphs& glyphs = glyphMapIt != glyphMap.end() ? glyphMapIt->second : Glyphs(); auto glyphPositionsIt = glyphPositions.find(layout.get<TextFont>()); const GlyphPositionMap& glyphPositionMap = glyphPositionsIt != glyphPositions.end() ? glyphPositionsIt->second : GlyphPositionMap(); for (auto it = features.begin(); it != features.end(); ++it) { auto& feature = *it; if (feature.geometry.empty()) continue; std::pair<Shaping, Shaping> shapedTextOrientations; optional<PositionedIcon> shapedIcon; // if feature has text, shape the text if (feature.text) { auto applyShaping = [&] (const std::u16string& text, WritingModeType writingMode) { const float oneEm = 24.0f; const Shaping result = getShaping( /* string */ text, /* maxWidth: ems */ layout.get<SymbolPlacement>() != SymbolPlacementType::Line ? layout.evaluate<TextMaxWidth>(zoom, feature) * oneEm : 0, /* lineHeight: ems */ layout.get<TextLineHeight>() * oneEm, /* anchor */ layout.evaluate<TextAnchor>(zoom, feature), /* justify */ layout.evaluate<TextJustify>(zoom, feature), /* spacing: ems */ util::i18n::allowsLetterSpacing(*feature.text) ? layout.evaluate<TextLetterSpacing>(zoom, feature) * oneEm : 0.0f, /* translate */ Point<float>(layout.evaluate<TextOffset>(zoom, feature)[0] * oneEm, layout.evaluate<TextOffset>(zoom, feature)[1] * oneEm), /* verticalHeight */ oneEm, /* writingMode */ writingMode, /* bidirectional algorithm object */ bidi, /* glyphs */ glyphs); return result; }; shapedTextOrientations.first = applyShaping(*feature.text, WritingModeType::Horizontal); if (util::i18n::allowsVerticalWritingMode(*feature.text) && textAlongLine) { shapedTextOrientations.second = applyShaping(util::i18n::verticalizePunctuation(*feature.text), WritingModeType::Vertical); } } // if feature has icon, get sprite atlas position if (feature.icon) { auto image = imageMap.find(*feature.icon); if (image != imageMap.end()) { shapedIcon = PositionedIcon::shapeIcon( imagePositions.at(*feature.icon), layout.evaluate<IconOffset>(zoom, feature), layout.evaluate<IconAnchor>(zoom, feature), layout.evaluate<IconRotate>(zoom, feature) * util::DEG2RAD); if (image->second->sdf) { sdfIcons = true; } if (image->second->pixelRatio != pixelRatio) { iconsNeedLinear = true; } else if (layout.get<IconRotate>().constantOr(1) != 0) { iconsNeedLinear = true; } } } // if either shapedText or icon position is present, add the feature if (shapedTextOrientations.first || shapedIcon) { addFeature(std::distance(features.begin(), it), feature, shapedTextOrientations, shapedIcon, glyphPositionMap, tileID, sourceID); } feature.geometry.clear(); } compareText.clear(); }