src/ldDocument.cc

branch
experimental
changeset 910
a6c180bffa12
parent 908
3b0b2b1738e9
--- a/src/ldDocument.cc	Wed Nov 05 17:48:11 2014 +0200
+++ b/src/ldDocument.cc	Thu Nov 06 13:51:09 2014 +0200
@@ -1373,6 +1373,8 @@
 // -----------------------------------------------------------------------------
 LDObjectList LDDocument::inlineContents (bool deep, bool renderinline)
 {
+	sweepBFC();
+
 	// Possibly substitute with logoed studs:
 	// stud.dat -> stud-logo.dat
 	// stud2.dat -> stud-logo2.dat
@@ -1387,41 +1389,42 @@
 			return g_logoedStud2->inlineContents (deep, renderinline);
 	}
 
-	LDObjectList objs, objcache;
-	bool invertnext = false;
+	LDObjectList objs;
+	QList<LDSubfilePtr> subfiles;
 
 	for (LDObjectPtr obj : objects())
 	{
-		// Handle invertnext
-		if (obj->type() == OBJ_BFC
-			and obj.staticCast<LDBFC>()->statement() == BFCStatement::InvertNext)
-		{
-			invertnext = true;
-			continue;
-		}
-
 		// Skip those without scemantic meaning
 		if (not obj->isScemantic())
 			continue;
-
+		
 		// Got another sub-file reference, inline it if we're deep-inlining. If not,
 		// just add it into the objects normally. Yay, recursion!
 		if (deep == true and obj->type() == OBJ_Subfile)
-		{
-			for (LDObjectPtr otherobj : obj.staticCast<LDSubfile>()->inlineContents (deep, renderinline))
-			{
-				if (invertnext)
-					otherobj->setBlockWinding (Winding (int (otherobj->blockWinding()) ^ 1));
-
-				objs << otherobj;
-			}
-
-			invertnext = false;
-		}
+			subfiles << obj.staticCast<LDSubfile>();
 		else
 			objs << obj->createCopy();
 	}
 
+	// Perform deep inlining
+	while (not subfiles.isEmpty())
+	{
+		QList<LDSubfilePtr> subfiles2;
+		
+		for (LDSubfilePtr& ref : subfiles)
+		{
+			for (LDObjectPtr obj : ref->inlineContents (false, renderinline))
+			{
+				if (obj->type() == OBJ_Subfile)
+					subfiles2 << obj.staticCast<LDSubfile>();
+				else
+					objs << obj;
+			}
+		}
+		
+		subfiles = subfiles2;
+	}
+
 	return objs;
 }
 
@@ -1641,10 +1644,12 @@
 
 			if (invertnext)
 			{
+				print ("sweepBFC: applying invertnext on %1\n", obj->id());
 				invertWinding (objwinding);
 				invertnext = false;
 			}
 
+			print ("sweepBFC: winding of %1 -> %2\n", obj->id(), int (objwinding));
 			obj->setBlockWinding (objwinding);
 		}
 	}

mercurial