Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
64fbf5ab
Commit
64fbf5ab
authored
Dec 19, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alignment of text
parent
015b6aeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
8 deletions
+68
-8
src/render/text/viewer.cpp
src/render/text/viewer.cpp
+64
-7
src/render/text/viewer.hpp
src/render/text/viewer.hpp
+4
-1
No files found.
src/render/text/viewer.cpp
View file @
64fbf5ab
...
...
@@ -220,14 +220,17 @@ void TextViewer::prepareElements(const String& text, const TextStyle& style, Con
void
TextViewer
::
prepareLines
(
RotatedDC
&
dc
,
const
String
&
text
,
const
TextStyle
&
style
)
{
scale
=
1
;
prepareLinesScale
(
dc
,
text
,
style
,
false
);
}
bool
TextViewer
::
prepareLinesScale
(
RotatedDC
&
dc
,
const
String
&
text
,
const
TextStyle
&
style
,
bool
stop_if_too_long
)
{
// Try to layout the text at the current scale
// find character sizes
vector
<
CharInfo
>
chars
;
elements
.
getCharInfo
(
dc
,
scale
,
0
,
text
.
size
(),
chars
);
// try to layout
prepareLinesScale
(
dc
,
chars
,
style
,
false
);
// align
alignLines
(
dc
,
chars
,
style
);
}
bool
TextViewer
::
prepareLinesScale
(
RotatedDC
&
dc
,
const
vector
<
CharInfo
>&
chars
,
const
TextStyle
&
style
,
bool
stop_if_too_long
)
{
// Try to layout the text at the current scale
// first line
lines
.
clear
();
Line
line
;
...
...
@@ -240,7 +243,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const String& text, const Text
size_t
word_start
=
0
;
// For each character ...
for
(
size_t
i
=
0
;
i
<
chars
.
size
()
;
++
i
)
{
CharInfo
&
c
=
chars
[
i
];
const
CharInfo
&
c
=
chars
[
i
];
// Should we break?
bool
break_now
=
false
;
bool
accept_word
=
false
;
// the current word should be added to the line
...
...
@@ -342,5 +345,59 @@ double TextViewer::lineRight(RotatedDC& dc, const TextStyle& style, double y) {
return
style
.
width
-
style
.
padding_right
;
// return style.mask.rowRight(y, dc.getInternalSize()) - style.padding_right;
}
ContourMask
::
ContourMask
()
{}
// MOVEME //@@
ContourMask
::~
ContourMask
()
{}
\ No newline at end of file
ContourMask
::~
ContourMask
()
{}
void
TextViewer
::
alignLines
(
RotatedDC
&
dc
,
const
vector
<
CharInfo
>&
chars
,
const
TextStyle
&
style
)
{
if
(
style
.
alignment
==
ALIGN_TOP_LEFT
)
return
;
// Find height of the text, don't count the last lines if they are empty
double
height
=
0
;
FOR_EACH_REVERSE
(
l
,
lines
)
{
height
=
l
.
top
+
l
.
line_height
;
if
(
l
.
line_height
)
break
;
// not an empty line
}
// amount to shift all lines vertically
RealSize
s
=
dc
.
getInternalSize
();
double
vdelta
=
align_delta_y
(
style
.
alignment
,
s
.
height
,
height
);
// align all lines
FOR_EACH
(
l
,
lines
)
{
l
.
top
+=
vdelta
;
// amount to shift all characters horizontally
double
width
=
l
.
positions
.
back
();
if
((
style
.
alignment
&
ALIGN_JUSTIFY
)
||
(
style
.
alignment
&
ALIGN_JUSTIFY_OVERFLOW
&&
width
>
s
.
width
))
{
// justify text
// justifying = true;
double
hdelta
=
s
.
width
-
width
;
// amount of space to distribute
int
count
=
(
int
)
l
.
positions
.
size
()
-
1
;
// distribute it among this many characters
if
(
count
==
0
)
count
=
1
;
// prevent div by 0
int
i
=
0
;
FOR_EACH
(
c
,
l
.
positions
)
{
c
+=
hdelta
*
i
++
/
count
;
}
}
else
if
(
style
.
alignment
&
ALIGN_JUSTIFY
)
{
// justify text, by words
// justifying = true;
double
hdelta
=
s
.
width
-
width
;
// amount of space to distribute
int
count
=
0
;
// distribute it among this many words
for
(
size_t
k
=
l
.
start
+
1
;
k
<
l
.
end
()
-
1
;
++
k
)
{
if
(
chars
[
k
].
break_after
==
BREAK_SOFT
)
++
count
;
}
if
(
count
==
0
)
count
=
1
;
// prevent div by 0
int
i
=
0
;
size_t
j
=
l
.
start
;
FOR_EACH
(
c
,
l
.
positions
)
{
c
+=
hdelta
*
i
/
count
;
if
(
j
<
l
.
end
()
&&
chars
[
j
++
].
break_after
==
BREAK_SOFT
)
i
++
;
}
}
else
{
// simple alignment
// justifying = false;
double
hdelta
=
align_delta_x
(
style
.
alignment
,
s
.
width
,
width
);
FOR_EACH
(
c
,
l
.
positions
)
{
c
+=
hdelta
;
}
}
}
// TODO : work well with mask
}
src/render/text/viewer.hpp
View file @
64fbf5ab
...
...
@@ -104,7 +104,10 @@ class TextViewer {
/// Prepare the lines, layout the text
void
prepareLines
(
RotatedDC
&
dc
,
const
String
&
text
,
const
TextStyle
&
style
);
/// Prepare the lines, layout the text; at a specific scale
bool
prepareLinesScale
(
RotatedDC
&
dc
,
const
String
&
text
,
const
TextStyle
&
style
,
bool
stop_if_too_long
);
bool
prepareLinesScale
(
RotatedDC
&
dc
,
const
vector
<
CharInfo
>&
chars
,
const
TextStyle
&
style
,
bool
stop_if_too_long
);
/// Align the lines within the textbox
void
alignLines
(
RotatedDC
&
dc
,
const
vector
<
CharInfo
>&
chars
,
const
TextStyle
&
style
);
/// Find the line the given index is on, returns the first line if the index is not found
const
Line
&
findLine
(
size_t
index
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment