| 1 |
/* |
| 2 |
* This file is part of the apvlv package |
| 3 |
* Copyright (C) <2010> <Alf> |
| 4 |
* |
| 5 |
* Contact: Alf <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License along |
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
* |
| 21 |
*/ |
| 22 |
/* @CPPFILE ApvlvTxt.cc |
| 23 |
* |
| 24 |
* Author: Alf <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <QFile> |
| 28 |
#include <QWebEngineSettings> |
| 29 |
#include <fstream> |
| 30 |
|
| 31 |
#include "ApvlvTxt.h" |
| 32 |
#include "ApvlvWebViewWidget.h" |
| 33 |
|
| 34 |
namespace apvlv |
| 35 |
{ |
| 36 |
FILE_TYPE_DEFINITION ("Web", ApvlvTXT, { ".txt", ".text" }); |
| 37 |
|
| 38 |
bool |
| 39 |
ApvlvTXT::pageText (int pn, const Rectangle &rect, std::string &text) |
| 40 |
{ |
| 41 |
QFile file (mUrl.path ()); |
| 42 |
if (file.open (QIODeviceBase::ReadOnly) == false) |
| 43 |
return false; |
| 44 |
|
| 45 |
auto bytes = file.readAll (); |
| 46 |
text.append (bytes.toStdString ()); |
| 47 |
file.close (); |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
bool |
| 52 |
ApvlvTXT::pageRenderToWebView (int pn, double zm, int rot, WebView *webview) |
| 53 |
{ |
| 54 |
auto settings = webview->settings (); |
| 55 |
settings->setDefaultTextEncoding ("UTF-8"); |
| 56 |
return ApvlvHTML::pageRenderToWebView (pn, zm, rot, webview); |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
// Local Variables: |
| 62 |
// mode: c++ |
| 63 |
// End: |