Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wordwrapping of subtitles. #422

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile.ffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ compile:
configure:
cd ffmpeg; \
CFLAGS="$(CFLAGS) ${INCLUDES}" \
LDFLAGS="" \
./configure \
./configure \
--extra-cflags="-mfpu=vfp -mfloat-abi=$(FLOAT) -mno-apcs-stack-check -mstructure-size-boundary=32 -mno-sched-prolog" \
--enable-cross-compile \
--extra-ldflags="--sysroot=$(SYSROOT) $(LDFLAGS)" \
--enable-shared \
--disable-static \
--arch=arm \
Expand All @@ -42,8 +42,8 @@ configure:
--enable-gpl \
--enable-version3 \
--enable-protocols \
--enable-libsmbclient \
--enable-libssh \
--disable-libsmbclient \
--disable-libssh \
--enable-nonfree \
--enable-openssl \
--enable-pthreads \
Expand Down
56 changes: 23 additions & 33 deletions Makefile.include
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
# Customised version for JX. Not to be pushed/pulled.

USE_BUILDROOT=0
FLOAT=hard

ifeq ($(USE_BUILDROOT), 1)
BUILDROOT :=/opt/xbmc-bcm/buildroot
SDKSTAGE :=$(BUILDROOT)/output/staging
TARGETFS :=$(BUILDROOT)/output/target
TOOLCHAIN :=$(BUILDROOT)/output/host/usr/
HOST :=arm-unknown-linux-gnueabi
SYSROOT :=$(BUILDROOT)/output/host/usr/arm-unknown-linux-gnueabi/sysroot
else
BUILDROOT :=/opt/bcm-rootfs
SDKSTAGE :=/opt/bcm-rootfs
TARGETFS :=/opt/bcm-rootfs
TOOLCHAIN :=/home/dc4/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/
HOST :=arm-linux-gnueabihf
#SYSROOT :=$(TOOLCHAIN)/arm-bcm2708hardfp-linux-gnueabi/sysroot
SYSROOT :=/opt/bcm-rootfs
endif
BUILDROOT := $(HOME)/dev/raspberry_pi/omxplayer_compiled
TOOLCHAIN := $(HOME)/dev/raspberry_pi/arm-linux-gnueabihf
HOST := arm-linux-gnueabihf
SYSROOT := $(HOME)/dev/raspberry_pi/rootfs

JOBS=7

CFLAGS := -isystem$(PREFIX)/include
CXXFLAGS := $(CFLAGS)
CPPFLAGS := $(CFLAGS)
LDFLAGS := -L$(BUILDROOT)/lib
LD := $(TOOLCHAIN)/bin/$(HOST)-ld --sysroot=$(SYSROOT)
CC := $(TOOLCHAIN)/bin/$(HOST)-gcc --sysroot=$(SYSROOT)
CXX := $(TOOLCHAIN)/bin/$(HOST)-g++ --sysroot=$(SYSROOT)
OBJDUMP := $(TOOLCHAIN)/bin/$(HOST)-objdump
RANLIB := $(TOOLCHAIN)/bin/$(HOST)-ranlib
STRIP := $(TOOLCHAIN)/bin/$(HOST)-strip
AR := $(TOOLCHAIN)/bin/$(HOST)-ar
CXXCP := $(CXX) -E
PATH := $(PREFIX)/bin:$(BUILDROOT)/output/host/usr/bin:$(PATH)
CFLAGS := -isystem$(PREFIX)/include
CXXFLAGS := $(CFLAGS)
CPPFLAGS := $(CFLAGS)
LDFLAGS := -L$(SYSROOT)/opt/vc/lib/
LD := $(TOOLCHAIN)/bin/$(HOST)-ld --sysroot=$(SYSROOT)
CC := $(TOOLCHAIN)/bin/$(HOST)-gcc --sysroot=$(SYSROOT)
CXX := $(TOOLCHAIN)/bin/$(HOST)-g++ --sysroot=$(SYSROOT)
OBJDUMP := $(TOOLCHAIN)/bin/$(HOST)-objdump
RANLIB := $(TOOLCHAIN)/bin/$(HOST)-ranlib
STRIP := $(TOOLCHAIN)/bin/$(HOST)-strip
AR := $(TOOLCHAIN)/bin/$(HOST)-ar
CXXCP := $(CXX) -E
PATH := $(PREFIX)/bin:$(BUILDROOT)/output/host/usr/bin:$(PATH)

CFLAGS += -pipe -mfloat-abi=$(FLOAT) -mcpu=arm1176jzf-s -fomit-frame-pointer -mabi=aapcs-linux -mtune=arm1176jzf-s -mfpu=vfp -Wno-psabi -mno-apcs-stack-check -g -mstructure-size-boundary=32 -mno-sched-prolog
LDFLAGS += -L$(SYSROOT)/lib -L$(SYSROOT)/lib/$(HOST) -L$(SYSROOT)/usr/lib/$(HOST)
INCLUDES += -isystem$(SYSROOT)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SYSROOT)/opt/vc/include/interface/vcos/pthreads -isystem$(SYSROOT)/opt/vc/include/interface/vmcs_host/linux -Ipcre/build -Iboost-trunk -I$(SYSROOT)/usr/include/freetype2/ -I$(SYSROOT)/usr/include/dbus-1.0 -I$(SYSROOT)/usr/lib/arm-linux-gnueabihf/dbus-1.0/include

CFLAGS += -pipe -mfloat-abi=$(FLOAT) -mcpu=arm1176jzf-s -fomit-frame-pointer -mabi=aapcs-linux -mtune=arm1176jzf-s -mfpu=vfp -Wno-psabi -mno-apcs-stack-check -g -mstructure-size-boundary=32 -mno-sched-prolog
LDFLAGS += -L$(SDKSTAGE)/lib -L$(SDKSTAGE)/usr/lib -L$(SDKSTAGE)/opt/vc/lib/ -Lpcre/build
#INCLUDES += -isystem$(SDKSTAGE)/usr/include -isystem$(SDKSTAGE)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -isystem$(SDKSTAGE)/usr/include/freetype2
INCLUDES += -isystem$(SDKSTAGE)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -Ipcre/build -Iboost-trunk -Ifreetype2/include
79 changes: 70 additions & 9 deletions SubtitleRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,78 @@ void SubtitleRenderer::destroy_vg() {

void SubtitleRenderer::
prepare(const std::vector<std::string>& text_lines) BOOST_NOEXCEPT {
const int n_lines = text_lines.size();
const int in_lines = text_lines.size();
TagTracker tag_tracker;
std::vector<InternalChar> converted_line;
int stored_lines = 0;

internal_lines_.resize(n_lines);
line_widths_.resize(n_lines);
line_positions_.resize(n_lines);
for (int i = 0; i < n_lines; ++i) {
internal_lines_[i] = get_internal_chars(text_lines[i], tag_tracker);
prepare_glyphs(internal_lines_[i]);
line_widths_[i] = get_text_width(internal_lines_[i]);
line_positions_[i].second = margin_bottom_ + (n_lines-i-1)*line_height_;
internal_lines_.clear();
line_widths_.clear();
line_positions_.clear();

for (int i = 0; i < in_lines; ++i) {
int cuts;
int width = 0;
int target_width = 0;

converted_line = get_internal_chars(text_lines[i], tag_tracker);

for (auto c = converted_line.begin(); c != converted_line.end(); ++c) {
if (glyphs_.find(*c) == glyphs_.end())
load_glyph(*c);

width += glyphs_.at(*c).advance;
}

// This word wrap routine could use a little optimisation, but I have no
// idea how the vector class is implemented, so...
if (centered_)
cuts = (width * 5) / (buffer_width_ * 4);
else
cuts = width / (buffer_width_ - (margin_left_ * 2));

auto start = converted_line.begin();
auto end = converted_line.begin();

target_width = width / (cuts + 1);

for (int j = 0; j < cuts; j++)
{
int current_width = 0;

// The while clause is for paranoia only. If the maths is right it should never get hit.
while (end != converted_line.end()) {
int advance = glyphs_.at(*end).advance;

current_width += advance;

// Note that Unicode contains other whitespace characters not tested for here.
if ((current_width >= target_width) && ((*end).codepoint() <= 0x20))
{
width -= current_width;
current_width -= advance;
internal_lines_.push_back(std::vector<InternalChar>(start, end));
line_widths_.push_back(current_width);
stored_lines++;

end++;
start = end;
break;
}

end++;
}
}

internal_lines_.push_back(std::vector<InternalChar>(start, converted_line.end()));
line_widths_.push_back(width);
stored_lines++;
}

line_positions_.resize(stored_lines);

for (int i = 0; i < stored_lines; ++i) {
line_positions_[i].second = margin_bottom_ + (stored_lines-i-1)*line_height_;
if (centered_)
line_positions_[i].first = buffer_width_/2 - line_widths_[i]/2;
else
Expand Down