summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Feng2018-05-27 23:38:30 +0800
committerJeffrey Feng2018-05-27 23:38:30 +0800
commitfeca6e428ef9655b8b8152accfdeafd527657e0d (patch)
tree20292225b523b570ca8a28f1fd2839db4832c7c2
downloadaur-feca6e428ef9655b8b8152accfdeafd527657e0d.tar.gz
texstudio with the LCD subpixel rendering backend of cairo applied to poppler
-rw-r--r--.SRCINFO50
-rw-r--r--.gitignore5
-rw-r--r--01-texstudio-bug-fix.patch47
-rw-r--r--02-subpixel-rendering-for-poppler-and-glib.patch309
-rw-r--r--03-cairo-backend-for-poppler-qt5.patch236
-rw-r--r--04-texstudio-use-poppler-lcd.patch95
-rw-r--r--PKGBUILD82
7 files changed, 824 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 00000000000..2bc0f6f2bd5
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,50 @@
+pkgbase = texstudio-lcd
+ pkgdesc = IDE for LaTeX documents with LCD subpixel rendering backend for embedded viewer
+ pkgver = 2.12.8
+ pkgrel = 1
+ url = http://texstudio.sourceforge.net/
+ arch = x86_64
+ license = GPL
+ makedepends = qt5-tools
+ makedepends = mercurial
+ makedepends = imagemagick
+ makedepends = librsvg
+ makedepends = git
+ makedepends = python
+ makedepends = icu
+ makedepends = python2
+ makedepends = gobject-introspection
+ makedepends = qt4
+ makedepends = qt5-base
+ makedepends = gtk2
+ makedepends = lcms2
+ makedepends = pkgconfig
+ makedepends = libjpeg
+ makedepends = gcc-libs
+ makedepends = cairo
+ makedepends = fontconfig
+ makedepends = openjpeg
+ depends = qt5-svg
+ depends = qt5-script
+ depends = libxkbcommon-x11
+ depends = hicolor-icon-theme
+ optdepends = evince-lcd-standalone: pdf reader with LCD subpixel rendering
+ optdepends = okular-lcd-standalone: QT pdf reader with LCD subpixel rendering
+ conflicts = texstudio
+ conflicts = texstudio-dark-git
+ replaces = texmakerx
+ source = git+https://github.com/texstudio-org/texstudio#commit=613d4e15b55c4c9b3978acca30742cdcfb61d052
+ source = http://poppler.freedesktop.org/poppler-0.43.0.tar.xz
+ source = 01-texstudio-bug-fix.patch
+ source = 02-subpixel-rendering-for-poppler-and-glib.patch
+ source = 03-cairo-backend-for-poppler-qt5.patch
+ source = 04-texstudio-use-poppler-lcd.patch
+ sha256sums = SKIP
+ sha256sums = SKIP
+ sha256sums = 78e242d233ce68a032d2fab5413e1658b952358d9cae71b7ec470c6adf95c0db
+ sha256sums = 608ecfee2e448b323623993072ae0ab80af0714ff19767eb0dc3a3c413c21279
+ sha256sums = 59e3ff8ea3b7e58a4d9e30a60b848fe8a6534b94025a08074488b747974b5626
+ sha256sums = 64a38f1d31bf0462348eb4997ef2da5e230c2b58573854e9ab9bf2ede4667725
+
+pkgname = texstudio-lcd
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..42ca741c9e5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+texstudio/
+src/
+pkg/
+*.tar.xz
+
diff --git a/01-texstudio-bug-fix.patch b/01-texstudio-bug-fix.patch
new file mode 100644
index 00000000000..d4fdfe66122
--- /dev/null
+++ b/01-texstudio-bug-fix.patch
@@ -0,0 +1,47 @@
+From: Jeffrey Feng <galago1992@gmail.com>
+Subject: [PATCH 1/4] texstudio bug fix -- Grammar and QSplitter
+---
+git diff --stat
+ src/configmanager.cpp | 2 +-
+ src/grammarcheck.cpp | 2 +-
+ src/minisplitter.cpp | 1 -
+ 3 files changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/src/configmanager.cpp b/src/configmanager.cpp
+index 41f2e496..f7e8b7a2 100644
+--- a/src/configmanager.cpp
++++ b/src/configmanager.cpp
+@@ -603,7 +603,7 @@ ConfigManager::ConfigManager(QObject *parent): QObject (parent),
+ #else
+ registerOption("Grammar/Language Tool URL", &grammarCheckerConfig->languageToolURL, "http://localhost:8081/", &pseudoDialog->lineEditGrammarLTUrl);
+ #endif
+- registerOption("Grammar/Language Tool Path", &grammarCheckerConfig->languageToolPath, "", &pseudoDialog->lineEditGrammarLTPath);
++ registerOption("Grammar/Language Tool Path", &grammarCheckerConfig->languageToolPath, "/usr/share/languagetool:/usr/share/java/languagetool/*", &pseudoDialog->lineEditGrammarLTPath);
+ registerOption("Grammar/Language Tool Arguments", &grammarCheckerConfig->languageToolArguments, "org.languagetool.server.HTTPServer -p 8081", &pseudoDialog->lineEditGrammarLTArguments);
+ registerOption("Grammar/Language Tool Java Path", &grammarCheckerConfig->languageToolJavaPath, "java", &pseudoDialog->lineEditGrammarLTJava);
+ registerOption("Grammar/Language Tool Autorun", &grammarCheckerConfig->languageToolAutorun, true, &pseudoDialog->checkBoxGrammarLTAutorun);
+diff --git a/src/grammarcheck.cpp b/src/grammarcheck.cpp
+index d3ae0978..4b3a3e6a 100644
+--- a/src/grammarcheck.cpp
++++ b/src/grammarcheck.cpp
+@@ -898,7 +898,7 @@ void GrammarCheckLanguageToolJSON::tryToStart()
+ }
+ triedToStart = true;
+ startTime = 0;
+- if (ltPath == "" || !QFileInfo(ltPath).exists()) return;
++ if (ltPath == "") return;
+ javaProcess = new QProcess();
+ connect(javaProcess, SIGNAL(finished(int)), javaProcess, SLOT(deleteLater()));
+ connect(this, SIGNAL(destroyed()), javaProcess, SLOT(deleteLater()));
+diff --git a/src/minisplitter.cpp b/src/minisplitter.cpp
+index f70eed7e..e19fcd61 100644
+--- a/src/minisplitter.cpp
++++ b/src/minisplitter.cpp
+@@ -72,7 +72,6 @@ void MiniSplitterHandle::resizeEvent(QResizeEvent *event)
+ else
+ setContentsMargins(0, 2, 0, 2);
+ setMask(QRegion(contentsRect()));
+- QSplitterHandle::resizeEvent(event);
+ }
+
+ void MiniSplitterHandle::paintEvent(QPaintEvent *event)
diff --git a/02-subpixel-rendering-for-poppler-and-glib.patch b/02-subpixel-rendering-for-poppler-and-glib.patch
new file mode 100644
index 00000000000..99656898458
--- /dev/null
+++ b/02-subpixel-rendering-for-poppler-and-glib.patch
@@ -0,0 +1,309 @@
+From: Jeffrey Feng <galago1992@gmail.com>
+Subject: [PATCH 2/4] subpixel rendering for poppler and poppler-glib
+---
+diff -rup a/ b/|diffstat
+ CMakeLists.txt | 1
+ glib/CMakeLists.txt | 1
+ glib/demo/render.c | 25 +++++++++++++++++---
+ glib/poppler-page.cc | 10 ++++++++
+ glib/poppler-page.h | 1
+ poppler/CairoFontEngine.cc | 6 ++--
+ poppler/CairoOutputDev.cc | 17 +++++++++++++
+ poppler/Gfx.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++
+ poppler/Gfx.h | 3 ++
+ poppler/Page.cc | 14 +++++++++++
+ poppler/Page.h | 3 ++
+ 11 files changed, 131 insertions(+), 6 deletions(-)
+
+diff -rup a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt 2016-04-29 06:13:57.000000000 +0800
++++ b/CMakeLists.txt 2018-05-22 23:05:18.907662448 +0800
+@@ -501,6 +501,7 @@ add_library(poppler STATIC ${poppler_SRC
+ else(MSVC)
+ add_library(poppler SHARED ${poppler_SRCS})
+ endif(MSVC)
++set_target_properties(poppler PROPERTIES OUTPUT_NAME "poppler-lcd")
+ set_target_properties(poppler PROPERTIES VERSION 60.0.0 SOVERSION 60)
+ target_link_libraries(poppler LINK_PRIVATE ${poppler_LIBS})
+ install(TARGETS poppler RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX})
+diff -rup a/glib/CMakeLists.txt b/glib/CMakeLists.txt
+--- a/glib/CMakeLists.txt 2015-05-15 02:23:07.000000000 +0800
++++ b/glib/CMakeLists.txt 2018-05-22 23:06:31.313659479 +0800
+@@ -81,6 +81,7 @@ set(poppler_glib_generated_SRCS
+ ${CMAKE_SOURCE_DIR}/poppler/CairoRescaleBox.cc
+ )
+ add_library(poppler-glib SHARED ${poppler_glib_SRCS} ${poppler_glib_generated_SRCS})
++set_target_properties(poppler-glib PROPERTIES OUTPUT_NAME "poppler-glib-lcd")
+ set_target_properties(poppler-glib PROPERTIES VERSION 8.7.0 SOVERSION 8)
+ target_link_libraries(poppler-glib poppler ${GLIB2_LIBRARIES} ${CAIRO_LIBRARIES} ${FREETYPE_LIBRARIES})
+ if(HAVE_PTHREAD)
+diff -rup a/glib/demo/render.c b/glib/demo/render.c
+--- a/glib/demo/render.c 2014-02-09 23:10:30.000000000 +0800
++++ b/glib/demo/render.c 2018-05-18 21:21:13.000000000 +0800
+@@ -82,12 +82,14 @@ pgd_render_start (GtkButton *button,
+ PgdRenderDemo *demo)
+ {
+ PopplerPage *page;
++ gboolean subpixel_rendering;
+ gdouble page_width, page_height;
+ gdouble width, height;
+ gint x, y;
+ gchar *str;
+ GTimer *timer;
+ cairo_t *cr;
++ cairo_font_options_t *fo;
+
+ page = poppler_document_get_page (demo->doc, demo->page);
+ if (!page)
+@@ -116,6 +118,21 @@ pgd_render_start (GtkButton *button,
+ width, height);
+ cr = cairo_create (demo->surface);
+
++ fo = cairo_font_options_create ();
++ cairo_get_font_options (cr, fo);
++
++ subpixel_rendering = poppler_page_support_subpixel_rendering (page);
++ // printf("subpixel_rendering %d\n", subpixel_rendering);
++ if (subpixel_rendering) {
++ cairo_set_source_rgb (cr, 1., 1., 1.);
++ cairo_paint (cr);
++ cairo_font_options_set_antialias (fo, CAIRO_ANTIALIAS_SUBPIXEL);
++ cairo_font_options_set_subpixel_order (fo, CAIRO_SUBPIXEL_ORDER_RGB);
++ }
++
++ cairo_set_font_options (cr, fo);
++ cairo_font_options_destroy (fo);
++
+ cairo_save (cr);
+ switch (demo->rotate) {
+ case 90:
+@@ -143,9 +160,11 @@ pgd_render_start (GtkButton *button,
+ poppler_page_render (page, cr);
+ cairo_restore (cr);
+
+- cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
+- cairo_set_source_rgb (cr, 1., 1., 1.);
+- cairo_paint (cr);
++ if (!subpixel_rendering) {
++ cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
++ cairo_set_source_rgb (cr, 1., 1., 1.);
++ cairo_paint (cr);
++ }
+
+ g_timer_stop (timer);
+
+diff -rup a/glib/poppler-page.cc b/glib/poppler-page.cc
+--- a/glib/poppler-page.cc 2016-03-02 07:35:24.000000000 +0800
++++ b/glib/poppler-page.cc 2018-05-18 21:21:13.000000000 +0800
+@@ -2424,3 +2424,13 @@ poppler_page_get_text_attributes_for_are
+
+ return g_list_reverse(attributes);
+ }
++
++gboolean
++poppler_page_support_subpixel_rendering (PopplerPage *page)
++{
++ CairoOutputDev *output_dev;
++ g_return_val_if_fail (POPPLER_IS_PAGE (page), FALSE);
++
++ output_dev = page->document->output_dev;
++ return page->page->supportSubpixelRendering(output_dev);
++}
+diff -rup a/glib/poppler-page.h b/glib/poppler-page.h
+--- a/glib/poppler-page.h 2016-03-02 07:35:24.000000000 +0800
++++ b/glib/poppler-page.h 2018-05-18 21:21:13.000000000 +0800
+@@ -109,6 +109,7 @@ GList *poppler_page_get_
+ void poppler_page_free_text_attributes (GList *list);
+ GList * poppler_page_get_text_attributes_for_area (PopplerPage *page,
+ PopplerRectangle *area);
++gboolean poppler_page_support_subpixel_rendering (PopplerPage *page);
+
+ /* A rectangle on a page, with coordinates in PDF points. */
+ #define POPPLER_TYPE_RECTANGLE (poppler_rectangle_get_type ())
+diff -rup a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
+--- a/poppler/CairoFontEngine.cc 2016-04-29 06:05:41.000000000 +0800
++++ b/poppler/CairoFontEngine.cc 2018-05-20 12:51:49.952696424 +0800
+@@ -132,7 +132,7 @@ CairoFont::getSubstitutionCorrection(Gfx
+ cairo_matrix_t m;
+ cairo_matrix_init_identity(&m);
+ cairo_font_options_t *options = cairo_font_options_create();
+- cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
++ cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_SLIGHT);
+ cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_OFF);
+ cairo_scaled_font_t *scaled_font = cairo_scaled_font_create(cairo_font_face, &m, &m, options);
+
+@@ -190,7 +190,7 @@ _ft_new_face_uncached (FT_Library lib,
+ }
+
+ font_face = cairo_ft_font_face_create_for_ft_face (face,
+- FT_LOAD_NO_HINTING |
++ FT_LOAD_TARGET_LIGHT |
+ FT_LOAD_NO_BITMAP);
+ if (cairo_font_face_set_user_data (font_face,
+ &_ft_cairo_key,
+@@ -359,7 +359,7 @@ _ft_new_face (FT_Library lib,
+ _ft_open_faces = l;
+
+ l->font_face = cairo_ft_font_face_create_for_ft_face (tmpl.face,
+- FT_LOAD_NO_HINTING |
++ FT_LOAD_TARGET_LIGHT |
+ FT_LOAD_NO_BITMAP);
+ if (cairo_font_face_set_user_data (l->font_face,
+ &_ft_cairo_key,
+diff -rup a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
+--- a/poppler/CairoOutputDev.cc 2016-04-29 06:05:11.000000000 +0800
++++ b/poppler/CairoOutputDev.cc 2018-05-18 21:21:13.000000000 +0800
+@@ -1402,6 +1402,7 @@ void CairoOutputDev::drawChar(GfxState *
+ void CairoOutputDev::endString(GfxState *state)
+ {
+ int render;
++ GfxFontType fontType;
+
+ if (!currentFont)
+ return;
+@@ -1419,6 +1420,18 @@ void CairoOutputDev::endString(GfxState
+ goto finish;
+ }
+
++ fontType = state->getFont()->getType();
++ // Do not enable subpixel rendering for type3 font
++ // For some reason it does not work
++ if (fontType == fontType3) {
++ cairo_save(cairo);
++ cairo_font_options_t *fo;
++ fo = cairo_font_options_create ();
++ cairo_get_font_options (cairo, fo);
++ cairo_font_options_set_antialias (fo, CAIRO_ANTIALIAS_DEFAULT);
++ cairo_set_font_options (cairo, fo);
++ }
++
+ if (!(render & 1)) {
+ LOG (printf ("fill string\n"));
+ cairo_set_source (cairo, fill_pattern);
+@@ -1469,6 +1482,10 @@ void CairoOutputDev::endString(GfxState
+ }
+
+ finish:
++ // pair with the previous cairo_save to disable subpixel rendering for type3 fonts
++ if (fontType == fontType3) {
++ cairo_restore(cairo);
++ }
+ gfree (glyphs);
+ glyphs = NULL;
+ if (use_show_text_glyphs) {
+diff -rup a/poppler/Gfx.cc b/poppler/Gfx.cc
+--- a/poppler/Gfx.cc 2016-03-17 03:16:12.000000000 +0800
++++ b/poppler/Gfx.cc 2018-05-18 21:21:13.000000000 +0800
+@@ -4726,6 +4726,62 @@ void Gfx::doImage(Object *ref, Stream *s
+ error(errSyntaxError, getPos(), "Bad image parameters");
+ }
+
++GBool Gfx::checkNormalBlendModeOnly(Object *str) {
++ // printf("check blender mode start\n");
++ char *cmd;
++ Object obj;
++ Object args[maxArgs];
++ int numArgs, i;
++ GBool onlyNormalBlendMode;
++ Parser myParser(xref, new Lexer(xref, str), gFalse);
++
++ numArgs = 0;
++ onlyNormalBlendMode = gTrue;
++
++ myParser.getObj(&obj);
++ while (!obj.isEOF()) {
++ if (obj.isCmd()) {
++ cmd = obj.getCmd();
++
++ if (strcmp(cmd, "gs") == 0) {
++ Object obj1, obj2;
++ GfxBlendMode mode;
++ if (res->lookupGState(args[0].getName(), &obj1)) {
++ if (!obj1.dictLookup("BM", &obj2)->isNull()) {
++ if (state->parseBlendMode(&obj2, &mode)) {
++ // printf("check blend mode: %d\n", mode);
++ onlyNormalBlendMode &= (mode == gfxBlendNormal);
++ }
++ }
++ obj2.free();
++ }
++ obj1.free();
++ }
++ obj.free();
++
++ for (i = 0; i < numArgs; ++i)
++ args[i].free();
++ numArgs = 0;
++
++ } else if (numArgs < maxArgs) {
++ args[numArgs++] = obj;
++ } else {
++ obj.free();
++ }
++
++ myParser.getObj(&obj);
++ }
++ obj.free();
++
++ if (numArgs > 0) {
++ for (i = 0; i < numArgs; ++i)
++ args[i].free();
++ }
++
++ return onlyNormalBlendMode;
++}
++
++
+ GBool Gfx::checkTransparencyGroup(Dict *resDict) {
+ // check the effect of compositing objects as a group:
+ // look for ExtGState entries with ca != 1 or CA != 1 or BM != normal
+diff -rup a/poppler/Gfx.h b/poppler/Gfx.h
+--- a/poppler/Gfx.h 2015-11-16 05:05:22.000000000 +0800
++++ b/poppler/Gfx.h 2018-05-18 21:21:13.000000000 +0800
+@@ -186,6 +186,9 @@ public:
+ // Get the current graphics state object.
+ GfxState *getState() { return state; }
+
++ // Check whether a stream only contains normal blend mode (to enable subpixel rendering)
++ GBool checkNormalBlendModeOnly(Object *str);
++
+ GBool checkTransparencyGroup(Dict *resDict);
+
+ void drawForm(Object *str, Dict *resDict, double *matrix, double *bbox,
+diff -rup a/poppler/Page.cc b/poppler/Page.cc
+--- a/poppler/Page.cc 2016-02-07 20:41:06.000000000 +0800
++++ b/poppler/Page.cc 2018-05-18 21:21:13.000000000 +0800
+@@ -370,6 +370,20 @@ Dict *Page::getResourceDictCopy(XRef *xr
+ return dict ? dict->copy(xrefA) : NULL;
+ }
+
++GBool Page::supportSubpixelRendering(OutputDev *out) {
++ GBool supported = gFalse;
++ Object obj;
++ PDFRectangle box;
++
++ contents.fetch(xref, &obj);
++ if (!obj.isNull()) {
++ Gfx gfx(doc, out, attrs->getResourceDict(), &box, NULL);
++ supported = gfx.checkNormalBlendModeOnly(&obj);
++ }
++ obj.free();
++ return supported;
++}
++
+ void Page::replaceXRef(XRef *xrefA) {
+ Object obj1;
+ Dict *pageDict = pageObj.getDict()->copy(xrefA);
+diff -rup a/poppler/Page.h b/poppler/Page.h
+--- a/poppler/Page.h 2015-11-16 05:05:22.000000000 +0800
++++ b/poppler/Page.h 2018-05-18 21:21:13.000000000 +0800
+@@ -179,6 +179,9 @@ public:
+ Dict *getResourceDict();
+ Dict *getResourceDictCopy(XRef *xrefA);
+
++ // Whether the content in this page supports subpixel rendering (lcdfilter)
++ GBool supportSubpixelRendering(OutputDev *out);
++
+ // Get annotations array.
+ Object *getAnnots(Object *obj, XRef *xrefA = NULL) { return annotsObj.fetch((xrefA == NULL) ? xref : xrefA, obj); }
+ // Add a new annotation to the page
diff --git a/03-cairo-backend-for-poppler-qt5.patch b/03-cairo-backend-for-poppler-qt5.patch
new file mode 100644
index 00000000000..2da34b3a3eb
--- /dev/null
+++ b/03-cairo-backend-for-poppler-qt5.patch
@@ -0,0 +1,236 @@
+From: Jeffrey Feng <galago1992@gmail.com>
+Subject: [PATCH 3/4] cairo backend for poppler-qt5
+---
+diff -rup a/qt5 b/qt5|diffstat
+ demos/viewer.cpp | 6 ++-
+ src/CMakeLists.txt | 15 +++++++
+ src/poppler-document.cc | 3 +
+ src/poppler-page.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++-
+ src/poppler-private.cc | 2 -
+ src/poppler-qt5.h | 3 +
+ tests/CMakeLists.txt | 4 ++
+ 7 files changed, 112 insertions(+), 4 deletions(-)
+
+diff -rup a/qt5/demos/viewer.cpp b/qt5/demos/viewer.cpp
+--- a/qt5/demos/viewer.cpp 2014-02-09 23:10:33.000000000 +0800
++++ b/qt5/demos/viewer.cpp 2018-05-20 11:50:24.585847554 +0800
+@@ -74,13 +74,17 @@ PdfViewer::PdfViewer()
+ m_settingsRenderBackendGrp->setExclusive(true);
+ act = settingsRenderMenu->addAction(tr("Splash"));
+ act->setCheckable(true);
+- act->setChecked(true);
+ act->setData(qVariantFromValue(0));
+ m_settingsRenderBackendGrp->addAction(act);
+ act = settingsRenderMenu->addAction(tr("Arthur"));
+ act->setCheckable(true);
+ act->setData(qVariantFromValue(1));
+ m_settingsRenderBackendGrp->addAction(act);
++ act = settingsRenderMenu->addAction(tr("Cairo"));
++ act->setCheckable(true);
++ act->setChecked(true);
++ act->setData(qVariantFromValue(2));
++ m_settingsRenderBackendGrp->addAction(act);
+ connect(m_settingsRenderBackendGrp, SIGNAL(triggered(QAction*)),
+ this, SLOT(slotRenderBackend(QAction*)));
+
+diff -rup a/qt5/src/CMakeLists.txt b/qt5/src/CMakeLists.txt
+--- a/qt5/src/CMakeLists.txt 2016-03-02 07:35:24.000000000 +0800
++++ b/qt5/src/CMakeLists.txt 2018-05-19 11:01:30.000000000 +0800
+@@ -6,6 +6,10 @@ include_directories(
+ ${Qt5Core_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
++if (HAVE_CAIRO)
++ include_directories(${CAIRO_INCLUDE_DIRS})
++ add_definitions(${CAIRO_CFLAGS})
++endif (HAVE_CAIRO)
+
+ set(poppler_qt5_SRCS
+ poppler-annotation.cc
+@@ -29,9 +33,20 @@ set(poppler_qt5_SRCS
+ poppler-media.cc
+ ArthurOutputDev.cc
+ )
++if (HAVE_CAIRO)
++ set(poppler_qt5_SRCS ${poppler_qt5_SRCS}
++ ${CMAKE_SOURCE_DIR}/poppler/CairoOutputDev.cc
++ ${CMAKE_SOURCE_DIR}/poppler/CairoRescaleBox.cc
++ ${CMAKE_SOURCE_DIR}/poppler/CairoFontEngine.cc
++ )
++endif(HAVE_CAIRO)
+ add_library(poppler-qt5 SHARED ${poppler_qt5_SRCS})
++set_target_properties(poppler-qt5 PROPERTIES OUTPUT_NAME "poppler-qt5-lcd")
+ set_target_properties(poppler-qt5 PROPERTIES VERSION 1.6.0 SOVERSION 1)
+ target_link_libraries(poppler-qt5 poppler ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Xml_LIBRARIES})
++if (HAVE_CAIRO)
++ target_link_libraries(poppler-qt5 ${CAIRO_LIBRARIES})
++endif (HAVE_CAIRO)
+ if(MSVC)
+ target_link_libraries(poppler-qt5 poppler ${poppler_LIBS})
+ endif(MSVC)
+diff -rup a/qt5/src/poppler-document.cc b/qt5/src/poppler-document.cc
+--- a/qt5/src/poppler-document.cc 2015-09-08 23:34:57.000000000 +0800
++++ b/qt5/src/poppler-document.cc 2018-05-19 11:04:11.000000000 +0800
+@@ -528,6 +528,9 @@ namespace Poppler {
+ ret << Document::SplashBackend;
+ #endif
+ ret << Document::ArthurBackend;
++#if defined(HAVE_CAIRO)
++ ret << Document::CairoBackend;
++#endif
+ return ret;
+ }
+
+diff -rup a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
+--- a/qt5/src/poppler-page.cc 2016-04-29 05:58:39.000000000 +0800
++++ b/qt5/src/poppler-page.cc 2018-05-20 12:26:07.000000000 +0800
+@@ -41,6 +41,7 @@
+ #include <QtGui/QPainter>
+
+ #include <config.h>
++#include <math.h>
+ #include <PDFDoc.h>
+ #include <Catalog.h>
+ #include <Form.h>
+@@ -54,7 +55,9 @@
+ #include <SplashOutputDev.h>
+ #include <splash/SplashBitmap.h>
+ #endif
+-
++#if defined(HAVE_CAIRO)
++#include <CairoOutputDev.h>
++#endif
+ #include "poppler-private.h"
+ #include "poppler-page-transition-private.h"
+ #include "poppler-page-private.h"
+@@ -406,6 +409,82 @@ QImage Page::renderToImage(double xres,
+ img = tmpimg;
+ break;
+ }
++ case Poppler::Document::CairoBackend:
++ {
++#if defined(HAVE_CAIRO)
++ CairoOutputDev *output_dev = new CairoOutputDev();
++ output_dev->startDoc(m_page->parentDoc->doc);
++ int buffer_width, buffer_height, rotate;
++ cairo_surface_t *surface;
++ cairo_t *cairo;
++ cairo_font_options_t *fo;
++ GBool subpixel_rendering;
++ // If w or h are -1, that indicates the whole page, so we need to
++ // calculate how many pixels that corresponds to. Otherwise, we can use w
++ // or h directly for our buffer size.
++ const QSize pageSize = this->pageSize();
++ if (w == -1) {
++ const double xscale = xres / 72.0;
++ const double width = pageSize.width();;
++ buffer_width = (int) ceil(width * xscale);
++ } else {
++ buffer_width = w;
++ }
++ if (h == -1) {
++ const double yscale = yres / 72.0;
++ const double height = pageSize.height();
++ buffer_height = (int) ceil(height * yscale);
++ } else {
++ buffer_height = h;
++ }
++
++ rotate = rotation + m_page->page->getRotate();
++
++ // FIXME: Okular never provides a rotation value, so I don't have any way
++ // of testing this right now. The result is that subpixels are ordered
++ // incorrectly when the page is rotated.
++
++ //if (rotate == 90 || rotate == 270) {
++ // const double temp = height;
++ // height = width;
++ // width = temp;
++ //}
++
++ img = QImage(buffer_width, buffer_height, QImage::Format_ARGB32);
++ img.fill(Qt::white); // Never transparent
++
++ surface = cairo_image_surface_create_for_data(
++ img.bits(),
++ CAIRO_FORMAT_ARGB32,
++ buffer_width, buffer_height,
++ img.bytesPerLine());
++
++ cairo = cairo_create(surface);
++ fo = cairo_font_options_create ();
++ cairo_get_font_options (cairo, fo);
++ subpixel_rendering = m_page->page->supportSubpixelRendering (output_dev);
++ if (subpixel_rendering) {
++ cairo_set_source_rgb (cairo, 1., 1., 1.);
++ cairo_font_options_set_antialias (fo, CAIRO_ANTIALIAS_SUBPIXEL);
++ cairo_font_options_set_subpixel_order (fo, CAIRO_SUBPIXEL_ORDER_RGB);
++ }
++ cairo_set_font_options (cairo, fo);
++ cairo_font_options_destroy (fo);
++
++ output_dev->setCairo(cairo);
++
++ m_page->parentDoc->doc->displayPageSlice(
++ output_dev, m_page->index + 1, xres, yres, rotation, false, true,
++ false, x, y, w, h);
++
++ // Clean up
++ output_dev->setCairo(NULL);
++ cairo_destroy(cairo);
++ cairo_surface_destroy(surface);
++ delete output_dev;
++#endif
++ break;
++ }
+ }
+
+ return img;
+@@ -448,6 +527,8 @@ bool Page::renderToPainter(QPainter* pai
+ painter->restore();
+ return true;
+ }
++ case Poppler::Document::CairoBackend:
++ return false;
+ }
+ return false;
+ }
+diff -rup a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
+--- a/qt5/src/poppler-private.cc 2015-09-08 23:31:07.000000000 +0800
++++ b/qt5/src/poppler-private.cc 2018-05-19 12:25:04.000000000 +0800
+@@ -234,7 +234,7 @@ namespace Debug {
+
+ void DocumentData::init()
+ {
+- m_backend = Document::SplashBackend;
++ m_backend = Document::CairoBackend;
+ paperColor = Qt::white;
+ m_hints = 0;
+ m_optContentModel = 0;
+diff -rup a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
+--- a/qt5/src/poppler-qt5.h 2015-09-02 05:46:49.000000000 +0800
++++ b/qt5/src/poppler-qt5.h 2018-05-19 11:12:36.000000000 +0800
+@@ -876,7 +876,8 @@ delete it;
+ */
+ enum RenderBackend {
+ SplashBackend, ///< Splash backend
+- ArthurBackend ///< Arthur (Qt) backend
++ ArthurBackend, ///< Arthur (Qt) backend
++ CairoBackend ///< Cairo backend
+ };
+
+ /**
+diff -rup a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt
+--- a/qt5/tests/CMakeLists.txt 2016-03-02 07:35:24.000000000 +0800
++++ b/qt5/tests/CMakeLists.txt 2018-05-20 11:46:08.806858043 +0800
+@@ -10,6 +10,10 @@ include_directories(
+ ${Qt5Xml_INCLUDE_DIRS}
+ ${Qt5Widgets_INCLUDE_DIRS}
+ )
++if (HAVE_CAIRO)
++ include_directories(${CAIRO_INCLUDE_DIRS})
++ add_definitions(${CAIRO_CFLAGS})
++endif (HAVE_CAIRO)
+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
diff --git a/04-texstudio-use-poppler-lcd.patch b/04-texstudio-use-poppler-lcd.patch
new file mode 100644
index 00000000000..a3599d70daa
--- /dev/null
+++ b/04-texstudio-use-poppler-lcd.patch
@@ -0,0 +1,95 @@
+From: Jeffrey Feng <galago1992@gmail.com>
+Subject: [PATCH 4/4] texstudio with the LCD subpixel rendering backend of cairo applied to poppler
+---
+git diff --stat
+ texstudio.pro | 2 +-
+ src/pdfviewer/pdfviewer.pri | 10 +++++++---
+ src/configdialog.ui | 4 ++--
+ src/pdfviewer/pdfrendermanager.cpp | 4 ++--
+ 4 files changed, 12 insertions(+), 8 deletions(-)
+
+diff --git a/texstudio.pro b/texstudio.pro
+index 74cd63c5..de977b74 100644
+--- a/texstudio.pro
++++ b/texstudio.pro
+@@ -414,7 +414,7 @@ exists(./.git) {
+ #QMAKE_CXXFLAGS_DEBUG += -Werror -Wall -Wextra -Winit-self -Wmain -Wmissing-include-dirs -Wtrigraphs -Wunused -Wunknown-pragmas -Wundef -Wpointer-arith -Wtype-limits -Wwrite-strings -Wclobbered -Wempty-body -Wsign-compare -Waddress -Wlogical-op -Winline
+ QMAKE_CXXFLAGS_DEBUG += -Wall -Wextra -Winit-self -Wmissing-include-dirs -Wtrigraphs -Wunused -Wunknown-pragmas -Wundef -Wpointer-arith -Wwrite-strings -Wempty-body -Wsign-compare -Waddress -Winline
+ QMAKE_CXXFLAGS += -std=c++0x
+-!win32: QMAKE_LFLAGS += -rdynamic # option not supported by mingw
++!win32: QMAKE_LFLAGS += -rdynamic -Wl,-rpath,$$(POPPLER_LIB_RPATH)# option not supported by mingw
+ else {
+ QMAKE_CXXFLAGS += -gstabs -g
+ QMAKE_LFLAGS -= -Wl,-s
+diff --git a/src/pdfviewer/pdfviewer.pri b/src/pdfviewer/pdfviewer.pri
+index 1e7aec94..42d7d4fa 100644
+--- a/src/pdfviewer/pdfviewer.pri
++++ b/src/pdfviewer/pdfviewer.pri
+@@ -53,7 +53,7 @@ isEmpty(NO_POPPLER_PREVIEW) {
+
+ CONFIG += link_pkgconfig
+
+- PKGCONFIG += $${poppler_qt_pkg}
++ #PKGCONFIG += $${poppler_qt_pkg}
+
+ !isEmpty(MXE){
+ message("Using MXE")
+@@ -69,8 +69,12 @@ isEmpty(NO_POPPLER_PREVIEW) {
+ }else{
+ PKG_CONFIG_EXE = "pkg-config"
+ }
+- system($${PKG_CONFIG_EXE} --atleast-version=0.24 $${poppler_qt_pkg}):DEFINES += HAS_POPPLER_24
+- system($${PKG_CONFIG_EXE} --atleast-version=0.31 $${poppler_qt_pkg}):DEFINES += HAS_POPPLER_31
++ #system($${PKG_CONFIG_EXE} --atleast-version=0.24 $${poppler_qt_pkg}):DEFINES += HAS_POPPLER_24
++ #system($${PKG_CONFIG_EXE} --atleast-version=0.31 $${poppler_qt_pkg}):DEFINES += HAS_POPPLER_31
++ DEFINES += HAS_POPPLER_24
++ DEFINES += HAS_POPPLER_31
++ INCLUDEPATH += $$(POPPLER_LIB_DIR)/../include/poppler/qt5
++ LIBS += -L$$(POPPLER_LIB_DIR) -lpoppler-qt5-lcd -lpoppler-lcd
+ }
+ } else {
+ DEFINES += NO_POPPLER_PREVIEW
+diff --git a/src/configdialog.ui b/src/configdialog.ui
+index 0f3cbe6f..23121ef6 100644
+--- a/src/configdialog.ui
++++ b/src/configdialog.ui
+@@ -4296,7 +4296,7 @@ them here.</string>
+ <widget class="QComboBox" name="comboBoxPDFRenderBackend">
+ <property name="toolTip">
+ <string>The Render Backend used by the PDF library poppler.
+-'Splash' is the default and suitable for most situations.
++'Cairo' is the default and suitable for LCD subpixel rendering.
+ If there are rendering issues, you may try the alternative 'Arthur' backend.
+ Note: Changing this setting will only affect documents that are opened afterwards.</string>
+ </property>
+@@ -4305,7 +4305,7 @@ Note: Changing this setting will only affect documents that are opened afterward
+ </property>
+ <item>
+ <property name="text">
+- <string notr="true">Splash</string>
++ <string notr="true">Cairo</string>
+ </property>
+ </item>
+ <item>
+diff --git a/src/pdfviewer/pdfrendermanager.cpp b/src/pdfviewer/pdfrendermanager.cpp
+index 2323252e..9b6b5da2 100644
+--- a/src/pdfviewer/pdfrendermanager.cpp
++++ b/src/pdfviewer/pdfrendermanager.cpp
+@@ -176,7 +176,7 @@ QSharedPointer<Poppler::Document> PDFRenderManager::loadDocument(const QString &
+
+ cachedNumPages = docPtr->numPages();
+
+- Poppler::Document::RenderBackend backend = Poppler::Document::SplashBackend;
++ Poppler::Document::RenderBackend backend = Poppler::Document::CairoBackend;
+ if (ConfigManagerInterface::getInstance()->getOption("Preview/RenderBackend").toInt() == 1) {
+ backend = Poppler::Document::ArthurBackend;
+ }
+@@ -227,7 +227,7 @@ QSharedPointer<Poppler::Document> PDFRenderManager::loadDocument(const QString &
+ error = FileIncomplete;
+ return QSharedPointer<Poppler::Document>();
+ }
+- doc->setRenderBackend(Poppler::Document::SplashBackend);
++ doc->setRenderBackend(Poppler::Document::CairoBackend);
+ doc->setRenderHint(Poppler::Document::Antialiasing);
+ doc->setRenderHint(Poppler::Document::TextAntialiasing);
+ #endif
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 00000000000..e093148b38a
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,82 @@
+# Maintainer: Jeffrey Feng <galago1992@gmail.com>
+
+pkgname=texstudio-lcd
+_pkgname=texstudio
+pkgver=2.12.8
+pkgrel=1
+pkgdesc="IDE for LaTeX documents with LCD subpixel rendering backend for embedded viewer"
+arch=('x86_64')
+url="http://texstudio.sourceforge.net/"
+license=('GPL')
+depends=('qt5-svg' 'qt5-script' 'libxkbcommon-x11' 'hicolor-icon-theme')
+makedepends=('qt5-tools' 'mercurial' 'imagemagick' 'librsvg' 'git' 'python' 'icu'
+ 'python2' 'gobject-introspection' 'qt4' 'qt5-base' 'gtk2' 'lcms2'
+ 'pkgconfig' 'libjpeg' 'gcc-libs' 'cairo' 'fontconfig' 'openjpeg')
+optdepends=('evince-lcd-standalone: pdf reader with LCD subpixel rendering'
+ 'okular-lcd-standalone: QT pdf reader with LCD subpixel rendering')
+conflicts=('texstudio' 'texstudio-dark-git')
+replaces=('texmakerx')
+_commit=613d4e15b55c4c9b3978acca30742cdcfb61d052
+source=("git+https://github.com/texstudio-org/texstudio#commit=$_commit"
+ "http://poppler.freedesktop.org/poppler-0.43.0.tar.xz"
+ 01-texstudio-bug-fix.patch
+ 02-subpixel-rendering-for-poppler-and-glib.patch
+ 03-cairo-backend-for-poppler-qt5.patch
+ 04-texstudio-use-poppler-lcd.patch)
+sha256sums=('SKIP'
+ 'SKIP'
+ '78e242d233ce68a032d2fab5413e1658b952358d9cae71b7ec470c6adf95c0db'
+ '608ecfee2e448b323623993072ae0ab80af0714ff19767eb0dc3a3c413c21279'
+ '59e3ff8ea3b7e58a4d9e30a60b848fe8a6534b94025a08074488b747974b5626'
+ '8ddd9417fe94557a9d545a9d9772e454297e11723757dc5be34a61190a1d8e54')
+
+pkgver() {
+ cd $_pkgname
+ git describe --tags
+}
+
+prepare() {
+ cd $_pkgname
+ patch -Np1 < ../01-texstudio-bug-fix.patch
+ patch -Np1 < ../04-texstudio-use-poppler-lcd.patch
+ cd $srcdir/poppler-0.43.0
+ patch -Np1<../02-subpixel-rendering-for-poppler-and-glib.patch
+ patch -Np1<../03-cairo-backend-for-poppler-qt5.patch
+}
+
+build() {
+ # build poppler (poppler > 0.43 fails to work with LCD subpixel rendering patch)
+ cd $srcdir
+ mkdir -p build&&cd $_
+ cmake ../poppler-0.43.0 \
+ -DCMAKE_INSTALL_PREFIX=$srcdir/usr \
+ -DENABLE_XPDF_HEADERS=ON \
+ -DENABLE_LIBOPENJPEG=FALSE \
+ -DBUILD_GTK_TESTS=OFF -DBUILD_QT4_TESTS=OFF \
+ -DBUILD_QT5_TESTS=OFF -DBUILD_CPP_TESTS=OFF
+ make install
+
+ # build texstudio
+ cd $srcdir/$_pkgname
+ POPPLER_LIB_RPATH=/usr/lib/texstudio/poppler-lcd \
+ POPPLER_LIB_DIR=$srcdir/usr/lib \
+ qmake-qt5 CONFIG-="debug" texstudio.pro
+ sed -i "s#--as-needed#--no-as-needed#g" Makefile
+ make
+}
+
+package() {
+ cd $_pkgname
+ make INSTALL_ROOT="${pkgdir}" install
+
+ libdir=$pkgdir/usr/lib/texstudio/poppler-lcd
+ mkdir -p $libdir
+ cp "$srcdir/usr/lib/libpoppler-"{qt5-lcd.so.1,lcd.so.60} $libdir
+
+ for res in $(/bin/ls /usr/share/icons/hicolor | grep '[0-9]\+x[0-9]\+'); do
+ mkdir -p "${pkgdir}"/usr/share/icons/hicolor/${res}/apps
+ convert -background none -density 1200 -resize ${res} \
+ "${pkgdir}"/usr/share/icons/hicolor/scalable/apps/texstudio.svg \
+ "${pkgdir}"/usr/share/icons/hicolor/${res}/apps/texstudio.png
+ done
+}