OpenBoard-org / OpenBoard

OpenBoard is a cross-platform interactive whiteboard application intended for use in a classroom setting.
https://openboard.ch/
GNU General Public License v3.0
2.37k stars 426 forks source link

Import of SVG / SMART Notebook files #404

Open GavinSmith0123 opened 3 years ago

GavinSmith0123 commented 3 years ago

Is it possible to import arbitrary SVG files into OpenBoard, and if not, what are the limitations on this?

I am using the package for Ubuntu openboard_ubuntu_18.04_1.5.3_amd64.deb (the earlier, official release didn't work for me).

Import of SVG files would be greatly useful for migrating SMART Notebook files.

The attached file contains an SVG of a file I extracted from a SMART Notebook file testpage.zip. OpenBoard appears to use SVG internally but I couldn't get the page to display by copying this SVG into one of the directories for OpenBoard and renaming it as something like page001.svg. openboard outputs an error: error parsing file "Premature end of document." when I try to open that page.

If this can be made to work, OpenBoard seems to be the most promising option for migrating away from SMART Notebook for an educational organization. I believe many organizations are looking to abandon SMART Notebook due to their move to a subscription-based business model (I'm not privy to all the details here). However, other options have imperfect support of importing SMART Notebook files: text formatting is often messed up. This seems unnecessary, as when you open the Notebook file as a .zip and look at the .svg pages individually, they display perfectly. SMART Notebook software itself can export to a *.iwb format, which also messes up text formatting.

The issue with text formatting appears to relate to the handling of the SVG <text> element (the page I attached uses such an element), and use of x and y attributes on contained <tspan> elements. This is not supported by the *.iwb format spec is linked here and SMART Notebook's export uses the <textarea> element instead.

So if OpenBoard had full support for <text> and <tspan>, that would be a big start.

SMART Notebook can also embed Flash objects, but these could be dropped when exporting is done.

GavinSmith0123 commented 3 years ago

After downloading and building the sources from master, I tried to find what is happening with the sample svg I posted.

A <text> element is processed by loadScene in src/adaptors/UBSvgSubsetAdaptor.cpp, calling textItemFromSvg. This appears to be the wrong function, though, as it doesn't handle any <tspan> elements. (<tspan> are dealt with elsewhere in the code, in adaptors/UBCFFSubsetAdaptor.cpp). textItemFromSvg chews through the rest of the file, leading to a

error parsing file  "Premature end of document."

error on return. There may be something wrong with the condition

    while (!(mXmlReader.isEndElement() && (mXmlReader.name() == "font" || mXmlReader.name() == "foreignObject")))

as when I add a debugging statement:

@@ -2648,6 +2654,7 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
         }

         mXmlReader.readNext();
+        qWarning() << "read " << mXmlReader.name();
         if (mXmlReader.isStartElement())
         {
             //for new documents from version 4.5.0

it shows elements after the <text> element being read:

read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "text"
read  ""
read  "line"
read  "line"
read  ""
read  "line"
read  "line"
read  ""
read  "line"
read  "line"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "text"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "tspan"
read  ""
read  "text"
read  ""
read  "g"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "g"
read  ""
read  "g"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "g"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "g"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "g"
read  ""
read  "polyline"
read  "polyline"
read  ""
read  "g"
read  ""
read  "svg"
read  ""
read  ""
error parsing file  "Premature end of document."

When I comment out the call to textItemFromSvg, though, other elements in the svg do show up in OpenBoard as manipulable elements.

GavinSmith0123 commented 3 years ago

I was experimenting with altering adaptors/UBSvgSubsetAdaptor.cpp but there's quite a lot of related code in adaptors/UBCFFSubsetAdaptor.cpp that do related things, such as repositionSvgItem and parseTextAttributes which deal with transform attributes on svg elements.

Could anybody advise me which file would be the best to base work on for opening SVG files, especially SVG files embedded in SMART Notebook files? Does UBCFFSubsetAdaptor.cpp have to be for importing CFF files (Common File Format, same as IWB I think) or could it be for SVG files in general? Does UBSvgSubsetAdaptor.cpp just work for a very specific subset of SVG and would extending it be a good idea or not?

GavinSmith0123 commented 3 years ago

Here is an update on what I've been able to implement. I could not get CFF files to work at all but did get the regular code for OpenBoard files to display my test page by replacing a page file like page000.svg and altering the code. I copied some of the code from UBCFFSubsetAdaptor.cpp.

What I have so far is obviously far from complete, and just deals with my test page, although not perfectly. I imported each <tspan> element as a separate editable text element, which is not perfect as this will make text harder to edit, but at least this allows arbitrary positioning with the x and y attributes. OpenBoard seems to lack support for fully-justified text, which would be necessary to implement the SVG textLength attribute correctly.

The core of the new code (diff attached) is in the new_textItemFromSvg function in UBSvgSubsetAdaptor.cpp.

svg-text.diff.txt

One major problem is that OpenBoard does not save the file correctly. It badly mangles drawings. See screen clippings before after

.

GavinSmith0123 commented 3 years ago

I've uploaded my work on adding support for SMART Notebook import to https://github.com/GavinSmith0123/OpenBoard-SMART.

With this code, I have been able to open some of my SMART Notebook files in OpenBoard. I used and adapted code from other parts of the source code including the CFF import.

It is buggy and incomplete, but at least it allows you to see what is in the files. Hopefully it can be gradually fixed to be usable.

It would be good if somebody with more knowledge of the OpenBoard code base could have a look at my changes to see how well they fit in with it and any future plans for the code.

If the CFF import doesn't work at all perhaps the code for this could be removed in the future.

kaamui commented 3 years ago

hello,

It is already possible to add arbitrary SVG files to the image library (in Desktop Mode for example) as long as they are written in a format that OpenBoard can interpret.

copyInImageLibrary

I don't know Smart notebook file format but the difficulty you encounter might be due to custom types SMART Notebook handle and that can't be converted to "standard" svg.

For example, the ubz attached to this post contains a page with multiple objects. One of them is an audio object that can only be interpreted by OpenBoard, so if you open the page_001.svg on your browser, you will see every object except the audio one.

10022021 1516.zip

Can you share a typical SMART notebook file so I can take a deeper look into it ?

thanks for your work.

GavinSmith0123 commented 3 years ago

The file extension is normally .notebook but I've changed it to .zip to upload it. I think this file shows the variety of features you find most often in SMART Notebook files. similarity.zip

GavinSmith0123 commented 3 years ago

I uploaded the wrong file, I meant to upload this one: similarity MASTER.zip