Drawing parser should be done. Untested.
Originally committed to SVN as r527.
This commit is contained in:
parent
4b8d7b4dc8
commit
0fa1abf273
4 changed files with 218 additions and 14 deletions
194
p-designer/ass_drawing.cpp
Normal file
194
p-designer/ass_drawing.cpp
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
// Copyright (c) 2006, Niels Martin Hansen
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#include "ass_drawing.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Point Four on the roadmap: code the ToString function
|
||||||
|
|
||||||
|
wxString AssDrawing::ToString()
|
||||||
|
{
|
||||||
|
return wxString(_T(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Point Two on the roadmap: code the FromString function
|
||||||
|
// "Steal" some ideas from RTS.cpp :P
|
||||||
|
|
||||||
|
// Attempt to read a point from string src.
|
||||||
|
// On success: Add point to target, "eat" point from src, increase where by chars eaten, return true.
|
||||||
|
// Assume first char is a non-space
|
||||||
|
static bool ReadPoint(wxString &src, int &where, std::vector<AssDrawingPoint> &target)
|
||||||
|
{
|
||||||
|
AssDrawingPoint p;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
bool isneg = false;
|
||||||
|
|
||||||
|
// Check for negativity
|
||||||
|
if (src[i] == '+') isneg = false, i++;
|
||||||
|
if (src[i] == '-') isneg = true, i++;
|
||||||
|
|
||||||
|
// Faster exit for non-digit things
|
||||||
|
if (!isdigit(src[i])) return false;
|
||||||
|
|
||||||
|
// This loop should terminate even if it hits end of string, since isdigit('\0')==false
|
||||||
|
while (isdigit(src[i])) i++;
|
||||||
|
p.x = src.Mid(0, i).ToLong();
|
||||||
|
if (isneg) p.x = -p.x;
|
||||||
|
|
||||||
|
// Error checking
|
||||||
|
if (!isspace(src[i])) return false;
|
||||||
|
|
||||||
|
// Find start of next number
|
||||||
|
while (isspace(src[i])) i++;
|
||||||
|
|
||||||
|
// Get second number
|
||||||
|
int j = i;
|
||||||
|
isneg = false;
|
||||||
|
if (src[j] == '+') isneg = false, j++;
|
||||||
|
if (src[j] == '-') isneg = true, j++;
|
||||||
|
while (isdigit(src[j])) j++;
|
||||||
|
p.y = src.Mid(j, j-i).ToLong();
|
||||||
|
if (isneg) p.y = -p.y;
|
||||||
|
if (!isspace(src[j])) return false;
|
||||||
|
while (isspace(src[j])) j++;
|
||||||
|
|
||||||
|
// Finish off
|
||||||
|
src = src.Mid(j);
|
||||||
|
target.push_back(p);
|
||||||
|
where += j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AssDrawing::FromString(wxString src)
|
||||||
|
{
|
||||||
|
data.clear();
|
||||||
|
|
||||||
|
// Counter for number of chars eaten
|
||||||
|
int where = 0;
|
||||||
|
|
||||||
|
src.Trim(false);
|
||||||
|
|
||||||
|
while (src.Len() > 0) {
|
||||||
|
AssDrawingSegment seg;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
// Next character should be a letter, read it
|
||||||
|
switch (src[i]) {
|
||||||
|
case 'm':
|
||||||
|
seg.type = SEGMENT_MOVE;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
seg.type = SEGMENT_MOVE_NOCLOSE;
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
seg.type = SEGMENT_LINE;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
seg.type = SEGMENT_BEZIER;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
seg.type = SEGMENT_BSPLINE;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
seg.type = SEGMENT_BSPLINE_EXTEND;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
seg.type = SEGMENT_BSPLINE_CLOSE;
|
||||||
|
goto skippoints;
|
||||||
|
default:
|
||||||
|
// something unknown, stop parsing
|
||||||
|
return where+1;
|
||||||
|
}
|
||||||
|
where++, i++;
|
||||||
|
while (isspace(src[i])) where++, i++;
|
||||||
|
src = src.Mid(i);
|
||||||
|
while (ReadPoint(src, where, seg.points);
|
||||||
|
skippoints:
|
||||||
|
data.push_back(seg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// These might be a bit redundant... save them for last
|
||||||
|
|
||||||
|
void AssDrawing::Collapse()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssDrawing::Expand()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// I suppose Rescale is just a matter of calculating the new scale, calling Stretch and setting the scale field
|
||||||
|
|
||||||
|
void AssDrawing::Rescale(int new_scale)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssDrawing::Stretch(float factor)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// A note on the following functions:
|
||||||
|
// According to VSFilter (last time I checked), the width and height of a drawing are calculated just by looking
|
||||||
|
// at the min and max X and Y values that appear in the drawing string. This is technically wrong (because of
|
||||||
|
// splines, those do funny things) but better do as the Romans do.
|
||||||
|
|
||||||
|
AssDrawingPoint AssDrawing::GetMinXY()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return AssDrawingPoint(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssDrawingPoint AssDrawing::GetMaxXY()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return AssDrawingPoint(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssDrawingPoint AssDrawing::GetExtents()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return AssDrawingPoint(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssDrawingPoint AssDrawing::GetCenterXY()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return AssDrawingPoint(0, 0);
|
||||||
|
}
|
|
@ -35,18 +35,19 @@
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
enum AssDrawingSegmentType {
|
enum AssDrawingSegmentType {
|
||||||
SEGMENT_MOVE, // m <x> <y>
|
SEGMENT_MOVE, // m <x> <y>
|
||||||
SEGMENT_MOVE_NOCLOSE, // n <x> <y>
|
SEGMENT_MOVE_NOCLOSE, // n <x> <y>
|
||||||
SEGMENT_LINE, // l <x> <y>
|
SEGMENT_LINE, // l <x> <y>
|
||||||
SEGMENT_BEZIER, // b <x1> <y1> <x2> <y2> <x3> <y3>
|
SEGMENT_BEZIER, // b <x1> <y1> <x2> <y2> <x3> <y3>
|
||||||
SEGMENT_SPLINE, // s <x1> <y2> <x2> <y2> <x3> <y3> [... <xN> <yN>]
|
SEGMENT_BSPLINE, // s <x1> <y2> <x2> <y2> <x3> <y3> [... <xN> <yN>]
|
||||||
SEGMENT_SPLINE_EXTEND, // p <x> <y>
|
SEGMENT_BSPLINE_EXTEND, // p <x> <y>
|
||||||
SEGMENT_SPLINE_CLOSE, // c
|
SEGMENT_BSPLINE_CLOSE, // c
|
||||||
// thought: maybe join the three last into one?
|
// thought: maybe join the three last into one? (gabest doesn't)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AssDrawingPoint {
|
struct AssDrawingPoint {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
AssDrawingPoint(int _x, int _y) { x = _x; y = _y; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AssDrawingSegment {
|
struct AssDrawingSegment {
|
||||||
|
@ -59,13 +60,18 @@ struct AssDrawing {
|
||||||
std::vector<AssDrawingSegment> data;
|
std::vector<AssDrawingSegment> data;
|
||||||
|
|
||||||
wxString ToString(); // stupid conversion to string, doesn't try to shorten things out
|
wxString ToString(); // stupid conversion to string, doesn't try to shorten things out
|
||||||
int FromString(wxString &src); // returns 0 on success, index+1 of offending character on fail
|
int FromString(wxString src); // returns 0 on success, index+1 of offending character on fail
|
||||||
|
|
||||||
void Collapse(); // try to join as many segments together as possible, without affecting the actual shape (eg. join "l 1 2 l 3 4" into "l 1 2 3 4")
|
void Collapse(); // try to join as many segments together as possible, without affecting the actual shape (eg. join "l 1 2 l 3 4" into "l 1 2 3 4")
|
||||||
void Expand(); // split into as many segments as possible, without creating any meaningless ones, such as null-moves (ie. expand "l 1 2 3 4" into "l 1 2 l 3 4")
|
void Expand(); // split into as many segments as possible, without creating any meaningless ones, such as null-moves (ie. expand "l 1 2 3 4" into "l 1 2 l 3 4")
|
||||||
|
|
||||||
void Rescale(int new_scale); // change the scale value, stretching the drawing to match the new one
|
void Rescale(int new_scale); // change the scale value, stretching the drawing to match the new one
|
||||||
void Stretch(float factor); // up/down scale the drawing by a factor
|
void Stretch(float factor); // up/down scale the drawing by a factor
|
||||||
|
|
||||||
|
AssDrawingPoint GetMinXY(); // get the lowest x and y coordinates present
|
||||||
|
AssDrawingPoint GetMaxXY(); // get the highest x and y coordinates present
|
||||||
|
AssDrawingPoint GetExtents(); // get the extents of the drawing as seen by VSFilter
|
||||||
|
AssDrawingPoint GetCenterXY(); // get the "center" of the drawing (as seen by VSFilter)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
OutputDirectory="Debug"
|
OutputDirectory="Debug"
|
||||||
IntermediateDirectory="Debug"
|
IntermediateDirectory="Debug"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
CharacterSet="2">
|
CharacterSet="1">
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;UNICODE"
|
||||||
MinimalRebuild="TRUE"
|
MinimalRebuild="TRUE"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
RuntimeLibrary="5"
|
RuntimeLibrary="5"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
Name="VCCustomBuildTool"/>
|
Name="VCCustomBuildTool"/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
OutputFile="$(OutDir)/p-designer.exe"
|
OutputFile="../bin/p-designer-debug.exe"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
GenerateDebugInformation="TRUE"
|
GenerateDebugInformation="TRUE"
|
||||||
ProgramDatabaseFile="$(OutDir)/p-designer.pdb"
|
ProgramDatabaseFile="$(OutDir)/p-designer.pdb"
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
OutputDirectory="Release"
|
OutputDirectory="Release"
|
||||||
IntermediateDirectory="Release"
|
IntermediateDirectory="Release"
|
||||||
ConfigurationType="1"
|
ConfigurationType="1"
|
||||||
CharacterSet="2">
|
CharacterSet="1">
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
Name="VCCustomBuildTool"/>
|
Name="VCCustomBuildTool"/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
OutputFile="$(OutDir)/p-designer.exe"
|
OutputFile="../bin/p-designer.exe"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
GenerateDebugInformation="TRUE"
|
GenerateDebugInformation="TRUE"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
|
@ -112,6 +112,9 @@
|
||||||
Name="Source Files"
|
Name="Source Files"
|
||||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||||
|
<File
|
||||||
|
RelativePath=".\ass_drawing.cpp">
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="Header Files"
|
Name="Header Files"
|
||||||
|
|
|
@ -24,6 +24,7 @@ Other stuff / wishlist:
|
||||||
* Maybe import outlines of one or more characters from a font to modify?
|
* Maybe import outlines of one or more characters from a font to modify?
|
||||||
(At least is possible with Win32 and Freetype2.)
|
(At least is possible with Win32 and Freetype2.)
|
||||||
* Convert segments between different types
|
* Convert segments between different types
|
||||||
|
* Binary operations with other shapes
|
||||||
|
|
||||||
Things to check:
|
Things to check:
|
||||||
* What happens when a drawing doesn't start with an 'm' command?
|
* What happens when a drawing doesn't start with an 'm' command?
|
||||||
|
|
Loading…
Reference in a new issue