MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / saveToCache

Method saveToCache

lib/Epub/Epub/css/CssParser.cpp:689–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

687}
688
689bool CssParser::saveToCache() const {
690 if (cachePath.empty()) {
691 return false;
692 }
693
694 HalFile file;
695 if (!Storage.openFileForWrite("CSS", cachePath + rulesCache, file)) {
696 return false;
697 }
698
699 // Write version
700 file.write(CssParser::CSS_CACHE_VERSION);
701
702 // Write rule count
703 const auto ruleCount = static_cast<uint16_t>(rulesBySelector_.size());
704 file.write(reinterpret_cast<const uint8_t*>(&ruleCount), sizeof(ruleCount));
705
706 // Write each rule: selector string + CssStyle fields
707 for (const auto& pair : rulesBySelector_) {
708 // Write selector string (length-prefixed)
709 const auto selectorLen = static_cast<uint16_t>(pair.first.size());
710 file.write(reinterpret_cast<const uint8_t*>(&selectorLen), sizeof(selectorLen));
711 file.write(reinterpret_cast<const uint8_t*>(pair.first.data()), selectorLen);
712
713 // Write CssStyle fields (all are POD types)
714 const CssStyle& style = pair.second;
715 file.write(static_cast<uint8_t>(style.textAlign));
716 file.write(static_cast<uint8_t>(style.fontStyle));
717 file.write(static_cast<uint8_t>(style.fontWeight));
718 file.write(static_cast<uint8_t>(style.textDecoration));
719 file.write(static_cast<uint8_t>(style.direction));
720
721 // Write CssLength fields (value + unit)
722 auto writeLength = [&file](const CssLength& len) {
723 file.write(reinterpret_cast<const uint8_t*>(&len.value), sizeof(len.value));
724 file.write(static_cast<uint8_t>(len.unit));
725 };
726
727 writeLength(style.textIndent);
728 writeLength(style.marginTop);
729 writeLength(style.marginBottom);
730 writeLength(style.marginLeft);
731 writeLength(style.marginRight);
732 writeLength(style.paddingTop);
733 writeLength(style.paddingBottom);
734 writeLength(style.paddingLeft);
735 writeLength(style.paddingRight);
736 writeLength(style.imageHeight);
737 writeLength(style.imageWidth);
738 file.write(static_cast<uint8_t>(style.display));
739 file.write(static_cast<uint8_t>(style.verticalAlign));
740
741 // Write defined flags as uint32_t
742 uint32_t definedBits = 0;
743 if (style.defined.textAlign) definedBits |= 1 << 0;
744 if (style.defined.fontStyle) definedBits |= 1 << 1;
745 if (style.defined.fontWeight) definedBits |= 1 << 2;
746 if (style.defined.textDecoration) definedBits |= 1 << 3;

Callers 1

parseCssFilesMethod · 0.80

Calls 4

openFileForWriteMethod · 0.80
emptyMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected