More double width character improvements

This commit is contained in:
Tom Z?hner
2019-08-31 17:28:33 +02:00
parent 684dbeb897
commit 851892e192
6 changed files with 64 additions and 44 deletions
Generated Vendored
+19 -12
View File
@@ -596,7 +596,9 @@ var Parser = /** @class */ (function () {
Parser.prototype.parse = function () {
if (this.parser.data.length > 1 && String.fromCharCode(this.parser.data[0]) === "{") {
this.parseLoop(false, true);
return Promise.all(this.parser._asyncTasks).then(function () { return; });
return Promise.all(this.parser._asyncTasks).then(function () {
return;
});
}
if (this.parser.version == null) {
throw new _Helper__WEBPACK_IMPORTED_MODULE_1__["RTFJSError"]("Not a valid rtf document");
@@ -850,23 +852,28 @@ var Parser = /** @class */ (function () {
if (!_Helper__WEBPACK_IMPORTED_MODULE_1__["Helper"]._isalpha(ch)) {
if (ch === "\'") {
var hex = this.readChar() + this.readChar();
this.readChar();
this.readChar();
var followingHex = this.readChar() + this.readChar();
if (this.parser.state.pap.charactertype === _Helper__WEBPACK_IMPORTED_MODULE_1__["Helper"].CHARACTER_TYPE.DOUBLE) {
// Character is defined as double width
this.readChar();
this.readChar();
var followingHex = this.readChar() + this.readChar();
hex += followingHex;
}
else if (this.parser.state.pap.charactertype == null
&& _Helper__WEBPACK_IMPORTED_MODULE_1__["Helper"]._parseHex(hex) >= 128
&& _Helper__WEBPACK_IMPORTED_MODULE_1__["Helper"]._parseHex(followingHex) < 128) {
// Character type is undefined, inferred as double width
hex += followingHex;
}
else {
// Character is single width, unread characters
for (var i = 0; i < 4; i++) {
this.unreadChar();
&& this.parser.pos + 4 < this.parser.data.length) {
// Character type is undefined, leading byte is in the correct range, might be double width
var start = this.readChar() + this.readChar();
if (start === "\\'") {
// This character is followed by another character, assuming double width
var followingHex = this.readChar() + this.readChar();
hex += followingHex;
}
else {
// Character is single width, unread characters
for (var i = 0; i < 2; i++) {
this.unreadChar();
}
}
}
param = _Helper__WEBPACK_IMPORTED_MODULE_1__["Helper"]._parseHex(hex);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+28 -21
View File
@@ -25,15 +25,15 @@ SOFTWARE.
*/
import cptable from "codepage";
import { Document } from "../Document";
import { Helper, RTFJSError } from "../Helper";
import { RenderChp } from "../renderer/RenderChp";
import { Renderer } from "../renderer/Renderer";
import { RenderPap } from "../renderer/RenderPap";
import { SymbolTable } from "../Symboltable";
import { GlobalState, State } from "./Containers";
import { DestinationFactory } from "./destinations/DestinationBase";
import { Destinations } from "./destinations/Destinations";
import {Document} from "../Document";
import {Helper, RTFJSError} from "../Helper";
import {RenderChp} from "../renderer/RenderChp";
import {Renderer} from "../renderer/Renderer";
import {RenderPap} from "../renderer/RenderPap";
import {SymbolTable} from "../Symboltable";
import {GlobalState, State} from "./Containers";
import {DestinationFactory} from "./destinations/DestinationBase";
import {Destinations} from "./destinations/Destinations";
export class Parser {
private inst: Document;
@@ -47,7 +47,9 @@ export class Parser {
public parse(): Promise<void> {
if (this.parser.data.length > 1 && String.fromCharCode(this.parser.data[0]) === "{") {
this.parseLoop(false, true);
return Promise.all(this.parser._asyncTasks).then(() => { return; });
return Promise.all(this.parser._asyncTasks).then(() => {
return;
});
}
if (this.parser.version == null) {
throw new RTFJSError("Not a valid rtf document");
@@ -324,22 +326,27 @@ export class Parser {
if (!Helper._isalpha(ch)) {
if (ch === "\'") {
let hex = this.readChar() + this.readChar();
this.readChar();
this.readChar();
const followingHex = this.readChar() + this.readChar();
if (this.parser.state.pap.charactertype === Helper.CHARACTER_TYPE.DOUBLE) {
// Character is defined as double width
this.readChar();
this.readChar();
const followingHex = this.readChar() + this.readChar();
hex += followingHex;
} else if (this.parser.state.pap.charactertype == null
&& Helper._parseHex(hex) >= 128
&& Helper._parseHex(followingHex) < 128) {
// Character type is undefined, inferred as double width
hex += followingHex;
} else {
// Character is single width, unread characters
for (let i = 0; i < 4; i++) {
this.unreadChar();
&& this.parser.pos + 4 < this.parser.data.length) {
// Character type is undefined, leading byte is in the correct range, might be double width
const start = this.readChar() + this.readChar();
if (start === "\\'") {
// This character is followed by another character, assuming double width
const followingHex = this.readChar() + this.readChar();
hex += followingHex;
} else {
// Character is single width, unread characters
for (let i = 0; i < 2; i++) {
this.unreadChar();
}
}
}
@@ -438,7 +445,7 @@ export class Parser {
break main_loop;
} else if (this.popState() === initialState) {
break main_loop;
}
}
break;
case "\\":
this.parseKeyword(!skip ? process : null);
@@ -1,29 +1,35 @@
<div style="margin-bottom: 10pt; min-height: 11pt; text-align: left;">
<span style="font-family: MS PGothic; font-size: 11pt;">要フャホ要ァクフ刑カオ洋
<span style="font-family: MS PGothic; font-size: 11pt;">要やフぎば要立クモフ刑香カルオ洋
</span>
<span style="font-family: Calibri; font-size: 11pt;">8
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">宮ニネ前察ツサ田ヌィスキヲアヌイテ予
<span style="font-family: MS PGothic; font-size: 11pt;">宮ニルネ前察モツサ田読物たすえこ大症イづょ予
</span>
<span style="font-family: Calibri; font-size: 11pt;">9
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">イョケヘクヤトニ優ゥケナニ。サャ輸ク奪都ツコ全炭熟ソノケ
<span style="font-family: MS PGothic; font-size: 11pt;">代レイル鈴式せはず間理わ米解ルと優勧併ラナニ報緒治そぎ著輸モクヱ奪都ツラコ全躍炭熟ょちにせ
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">優施「シ構集テア亀ニネヌ様カ界表イエレカゥ真
<span style="font-family: SimSun; font-size: 11pt;">。惑
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">ワモ優施いやレぞ構集テア項亀業レネラリ読様じ界表ござ視目カ自真万やれ野
</span>
<span style="font-family: Calibri; font-size: 11pt;">5
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">ュクシネアル子ャヌ型ヤ゙
<span style="font-family: MS PGothic; font-size: 11pt;">政クユシネ続撃句るゃ裁子ぎゆどや基練型ぶむあ
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">ナカ
<span style="font-family: SimSun; font-size: 11pt;">。十
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">ナ存
</span>
<span style="font-family: Calibri; font-size: 11pt;">7
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">職ツワルェ確想ミ終トォ覚ッネャ本ト富ゥッセフナ
<span style="font-family: MS PGothic; font-size: 11pt;">職可ろまほが育確想比ミ終夏き覚民な速本ゃト富朝ッラだフ打
</span>
<span style="font-family: Calibri; font-size: 11pt;">71
</span>
<span style="font-family: MS PGothic; font-size: 11pt;">修ヒコ
<span style="font-family: MS PGothic; font-size: 11pt;">修ねぜ
</span>
<span style="font-family: SimSun; font-size: 11pt;">。
</span>
</div>
<div style="margin-bottom: 10pt; min-height: 11pt; text-align: left;">