Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(developer): support export of visual keyboard when Keyman for Windows not installed #11244

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 122 additions & 89 deletions common/windows/delphi/visualkeyboard/VisualKeyboardExportHTML.pas
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(*
Name: VisualKeyboardExportHTML
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Documentation:
Description:
Create Date: 20 Jun 2006

Modified Date: 8 Jun 2012
Authors: mcdurdin
Related Files:
Dependencies:
Related Files:
Dependencies:

Bugs:
Todo:
Notes:
Bugs:
Todo:
Notes:
History: 20 Jun 2006 - mcdurdin - Initial version
23 Aug 2006 - mcdurdin - Initial refactor for new visual keyboard
04 Dec 2006 - mcdurdin - Support new XML+XSLT OSK export
Expand Down Expand Up @@ -50,7 +50,8 @@ implementation
Controls,
DebugPaths,
Dialogs,
ErrorControlledRegistry,
ErrorControlledRegistry,
KeymanPaths,
RegistryKeys,
Unicode,
utildir,
Expand All @@ -63,15 +64,30 @@ implementation
{ TVisualKeyboardExportHTML }

function GetOSKXSLPath: string;
var
keyman_root: string;
begin
with TRegistryErrorControlled.Create do // I2890
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly(SRegKey_KeymanEngine_LM) and ValueExists(SRegValue_RootPath)
then Result := IncludeTrailingPathDelimiter(ReadString(SRegValue_RootPath)) + 'xml\osk\'
else Result := ExtractFilePath(ParamStr(0)) + 'xml\osk\';
finally
Free;
Result := ExtractFilePath(ParamStr(0)) + 'xml\osk\';
if not DirectoryExists(Result) then
begin
if TKeymanPaths.RunningFromSource(keyman_root) then
begin
Result := keyman_root + 'windows\src\engine\xml\osk\';
end
else
begin
with TRegistryErrorControlled.Create do // I2890
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly(SRegKey_KeymanEngine_LM) and ValueExists(SRegValue_RootPath) then
Result := IncludeTrailingPathDelimiter(ReadString(SRegValue_RootPath)) + 'xml\osk\';
finally
Free;
end;

if not DirectoryExists(Result) then
Result := '';
end;
end;
Result := GetDebugPath('Debug_OSKXSLPath', Result, True);
end;
Expand Down Expand Up @@ -131,100 +147,117 @@ procedure TVisualKeyboardExportHTML.ExportToFile(FileName: WideString);
{ Structure for HTML keyboard: file + subdirectory with images; always output as UTF-8? }

stemp := ChangeFileExt(FileName, '') + '.xml';

with TVisualKeyboardExportXML.Create(FKbd) do
try
ExportToFile(stemp);
finally
Free;
end;

files := TStringList.Create;
try
doc := CreateDOMDocument;
with TVisualKeyboardExportXML.Create(FKbd) do
try
doc.async := False;
doc.validateOnParse := False;
doc.load(stemp);
xsldoc := ComsFreeThreadedDOMDocument.Create;
ExportToFile(stemp);
finally
Free;
end;

files := TStringList.Create;
try
doc := CreateDOMDocument;
try
xsldoc.async := False;
xsldoc.resolveExternals := True;
xsldoc.validateOnParse := False;
xsldoc.load(GetOSKXSLPath + 'osk.xsl');
doc.async := False;
doc.validateOnParse := False;
if not doc.load(stemp) then
begin
if doc.parseError <> nil then
begin
ShowMessage('Could not load XML: '+doc.parseError.reason);
Exit;
end;
end;
xsldoc := ComsFreeThreadedDOMDocument.Create;
try
xsldoc.async := False;
xsldoc.resolveExternals := True;
xsldoc.validateOnParse := False;
if not xsldoc.load(GetOSKXSLPath + 'osk.xsl') then
begin
if xsldoc.parseError <> nil then
begin
ShowMessage('Could not load transform '+GetOSKXSLPath + 'osk.xsl: '+xsldoc.parseError.reason);
Exit;
end;
end;

xsldoc.setProperty('SelectionNamespaces', 'xmlns:oskexportdetails=''http://www.tavultesoft.com/xml/oskexportdetails''');
xsldoc.setProperty('SelectionLanguage', 'XPath');
xsldoc.setProperty('SelectionNamespaces', 'xmlns:oskexportdetails=''http://www.tavultesoft.com/xml/oskexportdetails''');
xsldoc.setProperty('SelectionLanguage', 'XPath');

nodes := xsldoc.documentElement.selectNodes('//oskexportdetails:includefile');
for i := 0 to nodes.length - 1 do
files.Add(nodes.item[i].text);
nodes := xsldoc.documentElement.selectNodes('//oskexportdetails:includefile');
for i := 0 to nodes.length - 1 do
files.Add(nodes.item[i].text);

xslt := ComsXSLTemplate.Create;
xslt.stylesheet := xsldoc;
xslt := ComsXSLTemplate.Create;
xslt.stylesheet := xsldoc;

xslproc := xslt.createProcessor;
xslproc := xslt.createProcessor;

xslproc.input := doc;
xslproc.addParameter('graphical', FGraphical, '');
xslproc.addParameter('folders', FFolders, '');
xslproc.input := doc;
xslproc.addParameter('graphical', FGraphical, '');
xslproc.addParameter('folders', FFolders, '');

xslproc.transform;
FOutput := xslproc.output; // doc.transformNode(xsldoc);
xslproc.transform;
FOutput := xslproc.output; // doc.transformNode(xsldoc);
finally
xsldoc := nil;
end;
finally
xsldoc := nil;
doc := nil;
end;
finally
doc := nil;
end;

with TStringList.Create do
try
Text := FOutput;
SaveToFile(FileName, TEncoding.UTF8); // I3337
with TStringList.Create do
try
Text := FOutput;
SaveToFile(FileName, TEncoding.UTF8); // I3337
finally
Free;
end;

if FFolders then
begin
FSubdir := ChangeFileExt(FileName, '')+'_files';

if DirectoryExists(FSubdir) and not DirectoryEmpty(FSubdir) then
begin
if MessageDlg('The subdirectory "'+FSubdir+'" already exists. Images for the HTML file will be placed in this '+
'subdirectory. If you continue, any files currently in the directory will be deleted.'#13#10#13#10+
'Continue exporting and delete all existing files in the subdirectory?', mtConfirmation, mbOkCancel, 0) = mrCancel then Exit;
if not EmptyDirectory(FSubdir) then
if MessageDlg('The subdirectory "'+FSubdir+'" was not able to be emptied. Continue exporting anyway?',
mtConfirmation, mbOkCancel, 0) = mrCancel then Exit;
end;

CreateDir(FSubdir);
end
else
FSubdir := ExtractFileDir(FileName);

s := GetOSKXSLPath;
if FGraphical then
for i := 0 to files.Count - 1 do
CopyFile(PChar(s+files[i]), PChar(FSubDir+'\'+files[i]), True);
finally
Free;
files.Free;
end;

if FFolders then
begin
FSubdir := ChangeFileExt(FileName, '')+'_files';

if DirectoryExists(FSubdir) and not DirectoryEmpty(FSubdir) then
s := ChangeFileExt(stemp, '')+'_xml_files\';
if FGraphical then
if FindFirst(s + '*', 0, f) = 0 then
begin
if MessageDlg('The subdirectory "'+FSubdir+'" already exists. Images for the HTML file will be placed in this '+
'subdirectory. If you continue, any files currently in the directory will be deleted.'#13#10#13#10+
'Continue exporting and delete all existing files in the subdirectory?', mtConfirmation, mbOkCancel, 0) = mrCancel then Exit;
if not EmptyDirectory(FSubdir) then
if MessageDlg('The subdirectory "'+FSubdir+'" was not able to be emptied. Continue exporting anyway?',
mtConfirmation, mbOkCancel, 0) = mrCancel then Exit;
repeat
CopyFile(PChar(s+f.Name), PChar(FSubDir+'\'+f.Name), True);
until FindNext(f) <> 0;
FindClose(f);
end;
RecursiveDelete(ExcludeTrailingPathDelimiter(s));

CreateDir(FSubdir);
end
else
FSubdir := ExtractFileDir(FileName);

s := GetOSKXSLPath;
if FGraphical then
for i := 0 to files.Count - 1 do
CopyFile(PChar(s+files[i]), PChar(FSubDir+'\'+files[i]), True);
finally
files.Free;
DeleteFile(stemp);
end;

s := ChangeFileExt(stemp, '')+'_xml_files\';
if FGraphical then
if FindFirst(s + '*', 0, f) = 0 then
begin
repeat
CopyFile(PChar(s+f.Name), PChar(FSubDir+'\'+f.Name), True);
until FindNext(f) <> 0;
FindClose(f);
end;

DeleteFile(stemp);
RecursiveDelete(ExcludeTrailingPathDelimiter(s));
end;

end.
15 changes: 7 additions & 8 deletions common/windows/delphi/visualkeyboard/VisualKeyboardExportXML.pas
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(*
Name: VisualKeyboardExportXML
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Documentation:
Description:
Create Date: 4 Dec 2006

Modified Date: 26 Jun 2012
Authors: mcdurdin
Related Files:
Dependencies:
Related Files:
Dependencies:

Bugs:
Todo:
Notes:
Bugs:
Todo:
Notes:
History: 04 Dec 2006 - mcdurdin - Export to version 7, UTF-8, fix text encoding for key caps
22 Jan 2007 - mcdurdin - Export XML files to filename_xml_files subfolder
19 Mar 2007 - mcdurdin - I699 - Fix crash when exporting OSK to HTML/XML
Expand Down Expand Up @@ -65,7 +65,6 @@ function TVisualKeyboardExportXML.XMLWideString(FileName: WideString): WideStrin
nl: WideString = #13#10;
begin
s := '<?xml version="1.0" encoding="UTF-8" ?>' + nl;
s := s + '<!DOCTYPE visualkeyboard SYSTEM "http://www.tavultesoft.com/keymandev/visualkeyboard.dtd">' + nl;
s := s + '<visualkeyboard>' + nl;
s := s + ' <header>' + nl;
s := s + ' <version>'+SKeymanVersion70+'</version>' + nl;
Expand Down
1 change: 1 addition & 0 deletions developer/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ inst/setup.zip
inst/templates.wxs
inst/xml.wxs
inst/kmc.wxs
tike/xml/osk

# /developer/TIKE/
tike/stock.kct
Expand Down
1 change: 1 addition & 0 deletions developer/src/inst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ clean:
-del /Q cef.wxs
-del /Q templates.wxs
-del /Q kmc.wxs
-rd /s /q $(DEVELOPER_ROOT)\src\tike\xml\osk

test-releaseexists:
cd $(DEVELOPER_ROOT)\src\inst
Expand Down
3 changes: 3 additions & 0 deletions developer/src/inst/download.in.mak
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ clean-heat: clean-heat-kmc

heat-xml:
# We copy the files to a temp folder in order to exclude thumbs.db, .vs, etc from harvesting
# We also copy over the OSK files from Keyman Engine (#11199)
-rmdir /s/q $(KEYMAN_WIX_TEMP_XML)
mkdir $(KEYMAN_WIX_TEMP_XML)
xcopy $(KEYMAN_ROOT)\windows\src\engine\xml\osk $(DEVELOPER_ROOT)\src\tike\xml\osk\ /s /i
xcopy $(DEVELOPER_ROOT)\src\tike\xml\* $(KEYMAN_WIX_TEMP_XML)\ /s

-del /f /s /q $(KEYMAN_WIX_TEMP_XML)\Thumbs.db
-rmdir /s/q $(KEYMAN_WIX_TEMP_XML)\app\node_modules
-for /f %i in ('dir /a:d /s /b $(KEYMAN_WIX_TEMP_XML)\.vs') do rd /s /q %i
Expand Down
Loading