| |
| |
|
|
| |
| |
| void mergePalette(const TPaletteP &targetPalette, |
| std::map<int, int> &indexTable, |
| const TPaletteP &sourcePalette, |
| const std::set<int> &sourceIndices) { |
| assert(targetPalette); |
| assert(targetPalette->getPageCount() > 0); |
| |
| indexTable[0] = 0; |
| std::set<int>::const_iterator styleIt = sourceIndices.begin(); |
| for (styleIt; styleIt != sourceIndices.end(); ++styleIt) { |
| int srcStyleId = *styleIt; |
| if (srcStyleId == 0) continue; |
| assert(0 <= srcStyleId && srcStyleId < sourcePalette->getStyleCount()); |
| TColorStyle *srcStyle = sourcePalette->getStyle(srcStyleId); |
| assert(srcStyle); |
| TPalette::Page *page = sourcePalette->getStylePage(srcStyleId); |
| if (page) { |
| std::wstring pageName = page->getName(); |
| int j = 0; |
| for (j = 0; j < targetPalette->getPageCount(); j++) { |
| if (targetPalette->getPage(j)->getName() != pageName) continue; |
| break; |
| } |
| if (j < targetPalette->getPageCount()) |
| page = targetPalette->getPage(j); |
| else |
| page = targetPalette->addPage(pageName); |
| } else |
| page = targetPalette->getPage(0); |
| int tarStyleId = 0; |
| int i = 0; |
| for (i = 0; i < targetPalette->getStyleCount(); i++) |
| if (*srcStyle == *targetPalette->getStyle(i) && i == srcStyleId) break; |
| if (i < targetPalette->getStyleCount()) |
| tarStyleId = i; |
| else { |
| TColorStyle *dstStyle = srcStyle->clone(); |
| tarStyleId = targetPalette->addStyle(dstStyle); |
| page->addStyle(tarStyleId); |
| targetPalette->setDirtyFlag(true); |
| } |
| assert(indexTable.count(srcStyleId) == 0); |
| indexTable[srcStyleId] = tarStyleId; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| bool mergePalette_Overlap(const TPaletteP &dstPalette, |
| const TPaletteP &copiedPalette, |
| bool keepOriginalPalette) { |
| if (!dstPalette || !copiedPalette) return false; |
| |
| bool styleAdded = false; |
| |
| int dstStyleCount = dstPalette->getStyleCount(); |
| int copiedStyleCount = copiedPalette->getStyleCount(); |
| |
| |
| if (keepOriginalPalette) { |
| |
| |
| if (dstStyleCount >= copiedStyleCount) { |
| return false; |
| } |
| |
| else { |
| |
| for (int i = dstStyleCount; i < copiedStyleCount; i++) { |
| |
| TPalette::Page *tmpPage = copiedPalette->getStylePage(i); |
| |
| TColorStyle *tmpStyle = copiedPalette->getStyle(i)->clone(); |
| |
| int id = dstPalette->addStyle(tmpStyle); |
| |
| if (tmpPage) dstPalette->getPage(0)->addStyle(id); |
| } |
| |
| styleAdded = true; |
| } |
| } |
| |
| |
| else { |
| |
| if (dstStyleCount > copiedStyleCount) { |
| TPalette *tmpPalette = copiedPalette->clone(); |
| |
| |
| for (int i = copiedStyleCount; i < dstStyleCount; i++) { |
| TColorStyle *tmpStyle = dstPalette->getStyle(i)->clone(); |
| int id = tmpPalette->addStyle(tmpStyle); |
| |
| TPalette::Page *tmpPage = dstPalette->getStylePage(i); |
| if (!tmpPage) continue; |
| std::wstring pageName = tmpPage->getName(); |
| |
| int p; |
| for (p = 0; p < tmpPalette->getPageCount(); p++) { |
| if (tmpPalette->getPage(p)->getName() == pageName) break; |
| } |
| if (p != tmpPalette->getPageCount()) |
| tmpPalette->getPage(p)->addStyle(id); |
| else { |
| tmpPalette->addPage(pageName)->addStyle(id); |
| } |
| } |
| dstPalette->assign(tmpPalette); |
| |
| styleAdded = false; |
| } |
| |
| else { |
| dstPalette->assign(copiedPalette.getPointer()); |
| |
| styleAdded = (dstStyleCount < copiedStyleCount); |
| } |
| } |
| dstPalette->setDirtyFlag(true); |
| return styleAdded; |
| } |
| |