Fix timestamp normalization for old backend

presentation
Ulrich Huber 7 years ago
parent d5f948193c
commit 7d8de15d5d
  1. 18
      src/control/xojfile/LoadHandler.cpp
  2. 45
      src/control/xojfile/LoadHandlerHelper.cpp
  3. 2
      src/control/xojfile/LoadHandlerHelper.h
  4. 2
      src/control/xojfile/SaveHandler.cpp

@ -554,10 +554,22 @@ void LoadHandler::parseStroke()
stroke->setAudioFilename(fn);
}
int ts = 0;
if (LoadHandlerHelper::getAttribInt("ts", true, this, ts))
if (this->fileversion < 4)
{
int ts = 0;
if (LoadHandlerHelper::getAttribInt("ts", true, this, ts))
{
stroke->setTimestamp(ts * 1000);
}
}
else
{
stroke->setTimestamp(ts);
size_t ts = 0;
if (LoadHandlerHelper::getAttribSizeT("ts", true, this, ts))
{
stroke->setTimestamp(ts);
}
}
int fill = -1;

@ -187,3 +187,48 @@ bool LoadHandlerHelper::getAttribInt(const char* name, bool optional, LoadHandle
return true;
}
size_t LoadHandlerHelper::getAttribSizeT(const char* name, LoadHandler* loadHandler)
{
const char* attrib = getAttrib(name, false, loadHandler);
if (attrib == NULL)
{
error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is NULL") % name));
return 0;
}
char* ptr = NULL;
size_t val = g_ascii_strtoull(attrib, &ptr, 10);
if (ptr == attrib)
{
error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is \"{2}\"") % name % attrib));
}
return val;
}
bool LoadHandlerHelper::getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler, size_t& rValue)
{
const char* attrib = getAttrib(name, optional, loadHandler);
if (attrib == NULL)
{
if (!optional)
{
g_warning("Parser: attribute %s not found!", name);
}
return false;
}
char* ptr = NULL;
size_t val = strtoull(attrib, &ptr, 10);
if (ptr == attrib)
{
error("%s", FC(_F("Attribute \"{1}\" could not be parsed as size_t, the value is \"{2}\"") % name % attrib));
}
rValue = val;
return true;
}

@ -29,4 +29,6 @@ public:
static double getAttribDouble(const char* name, LoadHandler* loadHandler);
static int getAttribInt(const char* name, LoadHandler* loadHandler);
static bool getAttribInt(const char* name, bool optional, LoadHandler* loadHandler, int& rValue);
static size_t getAttribSizeT(const char* name, LoadHandler* loadHandler);
static bool getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler, size_t& rValue);
};

@ -93,7 +93,7 @@ void SaveHandler::prepareSave(Document* doc)
void SaveHandler::writeHeader()
{
this->root->setAttrib("creator", PROJECT_STRING);
this->root->setAttrib("fileversion", "3");
this->root->setAttrib("fileversion", "4");
this->root->addChild(new XmlTextNode("title", "Xournal++ document - see " PROJECT_URL));
}

Loading…
Cancel
Save