Skip to content

Commit

Permalink
#5612 - The file size is the same when saved to png (#5722)
Browse files Browse the repository at this point in the history
Co-authored-by: Natalia_Loginova1 <Natalia_Loginova1@epam.com>
  • Loading branch information
NataliaLoginova and Natalia_Loginova1 authored Oct 13, 2024
1 parent 5678990 commit aaade78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions packages/ketcher-core/src/application/ketcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { saveAs } from 'file-saver';
import { FormatterFactory, SupportedFormat } from './formatters';
import { GenerateImageOptions, StructService } from 'domain/services';

import { CoreEditor, Editor, defaultBondThickness } from './editor';
import { CoreEditor, Editor } from './editor';
import { Indigo } from 'application/indigo';
import { KetSerializer, MolfileFormat } from 'domain/serializers';
import { SGroup, Struct } from 'domain/entities';
Expand Down Expand Up @@ -465,7 +465,6 @@ export class Ketcher {
data: string,
options: GenerateImageOptions = {
outputFormat: 'png',
bondThickness: defaultBondThickness,
},
): Promise<Blob> {
let meta = '';
Expand Down
21 changes: 6 additions & 15 deletions packages/ketcher-react/src/script/ui/component/view/savebutton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
import {
OutputFormatType,
defaultBondThickness,
KetcherLogger,
} from 'ketcher-core';
import { KetcherLogger, GenerateImageOptions } from 'ketcher-core';
import { saveAs } from 'file-saver';

import React, { PropsWithChildren } from 'react';
Expand All @@ -28,11 +24,10 @@ import { SaverType } from './saveButton.types';
type Props = {
server?: any;
filename: string;
outputFormat?: OutputFormatType;
bondThickness?: number;
data: any;
type?: string;
mode?: string;
options?: GenerateImageOptions;
onSave?: () => void;
onError?: (err: any) => void;
className?: string;
Expand All @@ -47,11 +42,10 @@ const SaveButton = (props: SaveButtonProps) => {
const {
server,
filename = 'unnamed',
outputFormat,
bondThickness,
data,
type,
mode = 'saveFile',
options,
onSave = noop,
onError = noop,
className,
Expand All @@ -76,14 +70,11 @@ const SaveButton = (props: SaveButtonProps) => {

const saveImage = () => {
const ketcherInstance = getKetcherInstance();
if (outputFormat) {
if (options?.outputFormat) {
ketcherInstance
.generateImage(data, {
outputFormat,
bondThickness: bondThickness || defaultBondThickness,
})
.generateImage(data, options)
.then((blob) => {
saveAs(blob, `${filename}.${outputFormat}`);
saveAs(blob, `${filename}.${options.outputFormat}`);
onSave();
})
.catch((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,12 @@ class SaveDialog extends Component {

getButtons = () => {
const { disableControls, imageFormat, isLoading, structStr } = this.state;
const { formState, bondThickness } = this.props;
const { options, formState } = this.props;
const { filename, format } = formState.result;
const isCleanStruct = this.props.struct.isBlank();

options.outputFormat = imageFormat;

const savingStruct =
this.isBinaryCdxFormat(format) && !isLoading
? b64toBlob(structStr)
Expand Down Expand Up @@ -451,10 +453,9 @@ class SaveDialog extends Component {
buttons.push(
<SaveButton
mode="saveImage"
options={options}
data={structStr}
filename={filename}
outputFormat={imageFormat}
bondThickness={bondThickness}
key="save-image-button"
type={`image/${format}+xml`}
onSave={this.props.onOk}
Expand Down

0 comments on commit aaade78

Please sign in to comment.