Fix doc-info (pdf/xps/djvu)

This commit is contained in:
Andrey Shimagin 2022-03-27 17:51:44 +03:00
parent 352d9d51fa
commit 7e8e35122b
3 changed files with 168 additions and 74 deletions

View file

@ -586,6 +586,12 @@
"textSubject": "Subject",
"textSymbols": "Symbols",
"textTitle": "Title",
"textPageSize": "Page Size",
"textPdfVer": "PDF Version",
"textPdfTagged": "Tagged PDF",
"textFastWV": "Fast Web View",
"textYes": "Yes",
"textNo": "No",
"textTop": "Top",
"textUnitOfMeasurement": "Unit Of Measurement",
"textUploaded": "Uploaded",

View file

@ -1,20 +1,105 @@
import React, { Component } from "react";
import { observer, inject } from "mobx-react";
import DocumentInfo from "../../view/settings/DocumentInfo";
import { withTranslation } from 'react-i18next';
class DocumentInfoController extends Component {
constructor(props) {
super(props);
this.docProps = this.getDocProps();
this.pdfProps = this.getPdfProps();
this.docInfoObject = {};
this.getAppProps = this.getAppProps.bind(this);
if(this.docProps) {
this.modified = this.getModified();
this.modifiedBy = this.getModifiedBy();
this.creators = this.getCreators();
this.title = this.getTitle();
this.subject = this.getSubject();
this.description = this.getDescription();
this.created = this.getCreated();
this.updateFileInfo(this.docProps);
} else if (this.pdfProps) {
this.updatePdfInfo(this.pdfProps);
}
console.log(this.docInfoObject)
}
updateFileInfo(props) {
let value;
if(props) {
value = props.asc_getCreated();
if(value) this.docInfoObject.dateCreated = this.getModified(value);
value = props.asc_getModified();
if(value) this.docInfoObject.modifyDate = this.getModified(value);
value = props.asc_getLastModifiedBy();
if(value) this.docInfoObject.modifyBy = AscCommon.UserInfoParser.getParsedName(value);
value = props.asc_getTitle();
this.docInfoObject.title = value || '';
value = props.asc_getSubject();
this.docInfoObject.subject = value || '';
value = props.asc_getDescription();
this.docInfoObject.description = value || '';
value = props.asc_getCreator();
if(value) this.docInfoObject.creators = value;
}
}
updatePdfInfo(props) {
const { t } = this.props;
const _t = t("Settings", { returnObjects: true });
let value;
if(props) {
value = props.CreationDate;
if (value)
this.docInfoObject.dateCreated = this.getModified(new Date(value));
value = props.ModDate;
if (value)
this.docInfoObject.modifyDate = this.getModified(new Date(value));
if(props.PageWidth && props.PageHeight && (typeof props.PageWidth === 'number') && (typeof props.PageHeight === 'number')) {
let width = props.PageWidth,
heigth = props.PageHeight;
switch(Common.Utils.Metric.getCurrentMetric()) {
case Common.Utils.Metric.c_MetricUnits.cm:
width = parseFloat((width* 25.4 / 72000.).toFixed(2));
heigth = parseFloat((heigth* 25.4 / 72000.).toFixed(2));
break;
case Common.Utils.Metric.c_MetricUnits.pt:
width = parseFloat((width/100.).toFixed(2));
heigth = parseFloat((heigth/100.).toFixed(2));
break;
case Common.Utils.Metric.c_MetricUnits.inch:
width = parseFloat((width/7200.).toFixed(2));
heigth = parseFloat((heigth/7200.).toFixed(2));
break;
}
this.docInfoObject.pageSize = (width + ' ' + Common.Utils.Metric.getCurrentMetricName() + ' x ' + heigth + ' ' + Common.Utils.Metric.getCurrentMetricName());
} else this.docInfoObject.pageSize = null;
value = props.Title;
if(value) this.docInfoObject.title = value;
value = props.Subject;
if(value) this.docInfoObject.subject = value;
value = props.Author;
if(value) this.docInfoObject.author = value;
value = props.Version;
if(value) this.docInfoObject.version = value;
value = props.Tagged;
if (value !== undefined)
this.docInfoObject.tagged = (value===true ? _t.textYes : _t.textNo);
value = props.FastWebView;
if (value !== undefined)
this.docInfoObject.fastWebView = (value===true ? _t.textYes : _t.textNo);
}
}
@ -23,21 +108,29 @@ class DocumentInfoController extends Component {
return api.asc_getCoreProps();
}
getPdfProps() {
const api = Common.EditorApi.get();
return api.asc_getPdfProps();
}
getAppProps() {
const api = Common.EditorApi.get();
const appProps = api.asc_getAppProps();
let appName;
if (appProps) {
let appName =
appName =
(appProps.asc_getApplication() || "") +
(appProps.asc_getAppVersion() ? " " : "") +
(appProps.asc_getAppVersion() || "");
return appName;
} else if (this.pdfProps) {
appName = this.pdfProps ? this.pdfProps.Producer || '' : '';
return appName;
}
}
getModified() {
let valueModified = this.docProps.asc_getModified();
getModified(valueModified) {
const _lang = this.props.storeAppOptions.lang;
if (valueModified) {
@ -53,39 +146,6 @@ class DocumentInfoController extends Component {
}
}
getModifiedBy() {
let valueModifiedBy = this.docProps.asc_getLastModifiedBy();
if (valueModifiedBy) {
return AscCommon.UserInfoParser.getParsedName(valueModifiedBy);
}
}
getCreators() {
return this.docProps.asc_getCreator();
}
getTitle() {
return this.docProps.asc_getTitle();
}
getSubject() {
return this.docProps.asc_getSubject();
}
getDescription() {
return this.docProps.asc_getDescription();
}
getCreated() {
let value = this.docProps.asc_getCreated();
const _lang = this.props.storeAppOptions.lang;
if(value) {
return value.toLocaleString(_lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleTimeString(_lang, {timeStyle: 'short'});
}
}
componentDidMount() {
const api = Common.EditorApi.get();
api.startGetDocInfo();
@ -95,17 +155,11 @@ class DocumentInfoController extends Component {
return (
<DocumentInfo
getAppProps={this.getAppProps}
modified={this.modified}
modifiedBy={this.modifiedBy}
creators={this.creators}
created={this.created}
title={this.title}
subject={this.subject}
description={this.description}
docInfoObject={this.docInfoObject}
/>
);
}
}
export default inject("storeAppOptions")(observer(DocumentInfoController));
export default inject("storeAppOptions")(observer(withTranslation()(DocumentInfoController)));

View file

@ -7,6 +7,8 @@ const PageDocumentInfo = (props) => {
const { t } = useTranslation();
const _t = t("Settings", { returnObjects: true });
const storeInfo = props.storeDocumentInfo;
const fileType = storeInfo.dataDoc.fileType;
const dataApp = props.getAppProps();
const {
@ -17,6 +19,21 @@ const PageDocumentInfo = (props) => {
wordsCount,
} = storeInfo.infoObj;
const {
pageSize,
title,
subject,
description,
dateCreated,
modifyBy,
modifyDate,
author,
version,
tagged,
fastWebView,
creators
} = props.docInfoObject;
const dataDoc = JSON.parse(JSON.stringify(storeInfo.dataDoc));
const isLoaded = storeInfo.isLoaded;
@ -62,70 +79,87 @@ const PageDocumentInfo = (props) => {
<ListItem title={t('Settings.textWords')} after={isLoaded ? String(wordsCount) : _t.textLoading}></ListItem>
<ListItem title={t('Settings.textSymbols')} after={isLoaded ? String(symbolsCount) : _t.textLoading}></ListItem>
<ListItem title={t('Settings.textSpaces')} after={isLoaded ? String(symbolsWSCount) : _t.textLoading}></ListItem>
{pageSize && <ListItem title={t('Settings.textPageSize')} after={pageSize}></ListItem>}
</List>
{props.title ? (
{title ? (
<Fragment>
<BlockTitle>{_t.textTitle}</BlockTitle>
<BlockTitle>{t('Settings.textTitle')}</BlockTitle>
<List>
<ListItem title={props.title}></ListItem>
<ListItem title={title}></ListItem>
</List>
</Fragment>
) : null}
{props.subject ? (
{subject ? (
<Fragment>
<BlockTitle>{_t.textSubject}</BlockTitle>
<BlockTitle>{t('Settings.textSubject')}</BlockTitle>
<List>
<ListItem title={props.subject}></ListItem>
<ListItem title={subject}></ListItem>
</List>
</Fragment>
) : null}
{props.description ? (
{description ? (
<Fragment>
<BlockTitle>{_t.textComment}</BlockTitle>
<BlockTitle>{t('Settings.textComment')}</BlockTitle>
<List>
<ListItem title={props.description}></ListItem>
<ListItem title={description}></ListItem>
</List>
</Fragment>
) : null}
{props.modified ? (
{modifyDate ? (
<Fragment>
<BlockTitle>{_t.textLastModified}</BlockTitle>
<BlockTitle>{t('Settings.textLastModified')}</BlockTitle>
<List>
<ListItem title={props.modified}></ListItem>
<ListItem title={modifyDate}></ListItem>
</List>
</Fragment>
) : null}
{props.modifiedBy ? (
{modifyBy ? (
<Fragment>
<BlockTitle>{_t.textLastModifiedBy}</BlockTitle>
<BlockTitle>{t('Settings.textLastModifiedBy')}</BlockTitle>
<List>
<ListItem title={props.modifiedBy}></ListItem>
<ListItem title={modifyBy}></ListItem>
</List>
</Fragment>
) : null}
{props.created ? (
{dateCreated ? (
<Fragment>
<BlockTitle>{_t.textCreated}</BlockTitle>
<BlockTitle>{t('Settings.textCreated')}</BlockTitle>
<List>
<ListItem title={props.created}></ListItem>
<ListItem title={dateCreated}></ListItem>
</List>
</Fragment>
) : null}
{dataApp ? (
<Fragment>
<BlockTitle>{_t.textApplication}</BlockTitle>
<BlockTitle>{t('Settings.textApplication')}</BlockTitle>
<List>
<ListItem title={dataApp}></ListItem>
</List>
</Fragment>
) : null}
{props.creators ? (
{fileType === 'xps' && author ? (
<Fragment>
<BlockTitle>{_t.textAuthor}</BlockTitle>
<BlockTitle>{t('Settings.textAuthor')}</BlockTitle>
<List>
<ListItem title={author}></ListItem>
</List>
</Fragment>
) : null}
{ fileType === 'pdf' ? (
<List>
<ListItem title={t('Settings.textAuthor')} after={author} />
<ListItem title={t('Settings.textPdfVer')} after={version} />
<ListItem title={t('Settings.textPdfTagged')} after={tagged} />
<ListItem title={t('Settings.textFastWV')} after={fastWebView} />
</List>
) : null}
{creators ? (
<Fragment>
<BlockTitle>{t('Settings.textAuthor')}</BlockTitle>
<List>
{
props.creators.split(/\s*[,;]\s*/).map(item => {
return <ListItem title={item}></ListItem>
creators.split(/\s*[,;]\s*/).map(item => {
return <ListItem key="item" title={item}></ListItem>
})
}
</List>