- if (rt == BASECLASS) {
- static char const * s = "Margin Static\n"
- "LatexType Paragraph\n"
- "LatexName dummy\n"
- "Align Block\n"
- "AlignPossible Left, Right, Center\n"
- "LabelType No_Label\n"
- "End";
- istringstream ss(s);
- Lexer lex(textClassTags, sizeof(textClassTags) / sizeof(textClassTags[0]));
- lex.setStream(ss);
- Layout lay;
- lay.setName(emptylayout_);
- if (!readStyle(lex, lay)) {
- // The only way this happens is because the hardcoded layout above
- // is wrong.
- BOOST_ASSERT(false);
- }
- layoutlist_.push_back(boost::shared_ptr<Layout>(new Layout(lay)));
+ if (rt == BASECLASS && !hasLayout(plain_layout_))
+ layoutlist_.push_back(createBasicLayout(plain_layout_));
+
+ Lexer lexrc(textClassTags);
+ lexrc.setFile(filename);
+ ReturnValues retval = read(lexrc, rt);
+
+ LYXERR(Debug::TCLASS, "Finished reading " + translateRT(rt) + ": " +
+ to_utf8(makeDisplayPath(filename.absFilename())));
+
+ if (retval != FORMAT_MISMATCH)
+ return retval == OK;
+
+ bool const worx = convertLayoutFormat(filename, rt);
+ if (!worx) {
+ lyxerr << "Unable to convert " << filename <<
+ " to format " << FORMAT << std::endl;
+ return false;
+ }
+ return true;
+}
+
+
+bool TextClass::validate(std::string const & str)
+{
+ TextClass tc;
+ return tc.read(str, VALIDATION);
+}
+
+
+bool TextClass::read(std::string const & str, ReadType rt)
+{
+ Lexer lexrc(textClassTags);
+ istringstream is(str);
+ lexrc.setStream(is);
+ ReturnValues retval = read(lexrc, rt);
+
+ if (retval != FORMAT_MISMATCH)
+ return retval == OK;
+
+ // write the layout string to a temporary file
+ FileName const tempfile = FileName::tempName("TextClass_read");
+ ofstream os(tempfile.toFilesystemEncoding().c_str());
+ if (!os) {
+ LYXERR0("Unable to create temporary file");
+ return false;
+ }
+ os << str;
+ os.close();
+
+ // now try to convert it
+ bool const worx = convertLayoutFormat(tempfile, rt);
+ if (!worx) {
+ LYXERR0("Unable to convert internal layout information to format "
+ << FORMAT);