Swift/macOS: how to open odt (open document format) in Text View? - nsattributedstring

I'm trying to make a small macOS viewer app that will display the content of ODT (Open Document) files but not allow editing in the way that TextEdit does. With the help of an online tutorial I've put together an RTF viewer that includes this code in Document.swift:
override func read(from data: Data, ofType typeName: String) throws {
if let contents = NSAttributedString(rtf: data, documentAttributes: nil) {
text = contents
}
}
What I can't figure out is how to make the program read ODT data instead of RTF data, and I can't find any documentation that helps out. So my question is: How can I rewrite that code to read in an ODT file instead of an RTF file?

Override read(from url: … instead of read(from data: … and use NSAttributedString's init(url:options:documentAttributes:).
override func read(from url: URL, ofType typeName: String) throws {
text = try NSAttributedString(url: url, options: [:], documentAttributes: nil)
}

Related

Save text file with code page UTF-8 in Axapta 3.0

How do I make a text file with code page UTF-8 in Axapta 3.0?
I cannot use
myFile = new CommaIo(myFileName, 'W', 65001);
as we can in newer versions of Axapta. In Axapta 3.0 new CommaIo only have the first two parameters.
I've not worked in 3.0, but I have a few ideas for you that might send you the right way.
1) Do you have CommaTextIo or TextIo? Those are the objects where you can specify a code page.
2) Look in the AOT and see if you have a macro called #File, and inside if you have #utf8Format(65001), use the X-Ref (or Ctrl+F) to find other places in the system that use it. Then you can see how they might accomplish UTF-8
3) See if you can combine CommaIo with some .NET code, or just manually generated a CSV. Perhaps generate your CSV and write it, then read it and re-write it using a method like below (from MetadataXMLGenerator job):
void write(str _directory, str _name, str _text)
{
str path;
;
_text = System.Text.RegularExpressions.Regex::Replace(_text, '\n', '\r\n');
if (!System.IO.Directory::Exists(_directory))
{
System.IO.Directory::CreateDirectory(_directory);
}
path = System.IO.Path::Combine(_directory, _name);
System.IO.File::WriteAllText(path, _text, System.Text.Encoding::get_UTF8());
}

Render PDF from ISML and retrieve binary data

our REST-API should deliver a PDF based on an HTML template.
Our intention is to generate the HTML using ISML, stuff it into the PDF processor and grab the output for the REST response.
What is the best way to implement that with Intershop 7.9?
Rendering the PDF is easy to accomplish using the Intershop PDF creation documentation.
Getting the HTML from an ISML template is more tricky, mostly because of missing examples. But in the ISH code there are two example classes hidden:
PageEntryPoint2PDFInteractionProcessor:TemplateCallable
MailMgrImpl:MailTemplateCallable
Both can grab HTML from ISML coming from two different places.
LocaleMgr localeMgr = NamingMgr.getManager(LocaleMgr.class);
String webpageContent = "";
// put some demo stuff into the PD
PipelineDictionary dict = new PipelineDictionaryImpl();
dict.put("foo", "foo");
Request request = Request.getCurrent();
ExecutorService executorService = Executors.newCachedThreadPool();
try {
// demo code, you might want to use another template than Empty.isml
TemplateCallable callable = new TemplateCallable("Empty", localeMgr,
dict, request);
Future<ServletResponse> future = executorService.submit(callable);
ServletResponse fwResponse = future.get();
webpageContent = fwResponse.getContent();
} catch (Exception e) {
Logger.error(this, "Error while getting template render result.");
}
The code for the Callable-Class you on can derive from the example classes I mentioned above.

Read (audio) file from subfolder in AndroidAssets in Xamarin.Forms

I try to eneable audio in my Xamarin.Forms application. I want to have the audio files in a Subfolderof the Assetsfolder like this Assets/Subfolder/Audio.mp3
I have found a plugin SimpleAudioPlayer which provide an example.
The following code works like provided.
var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
player.Load("Audio.mp3");
Now I want to place the audio file in a subfolder and I tried to call
player.Load("Subfolder/Audio.mp3");
But I get an Java.IO.FileNotFoundException
I looked then into the implementation of the Load function and I fould the following code
public bool Load(string fileName)
{
player.Reset();
AssetFileDescriptor afd = Android.App.Application.Context.Assets.OpenFd(fileName);
player?.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
return PreparePlayer();
}
where the filename is pasted to the Assets.OpenFd() function. which returns an AndroidFileDesriptor
The documentation does not really provide any information from Microsoft and from the Android site.
My questions are
How can I receive the file from the subfolder in Android Assets?
What can I paste into the Assets.OpenFd() function (subfolders etc)?
I would appreciate any advice, since after a long time trying to resolve it I don't really have an idea.
According to the docs of the package, you won't be able to do just that because you have to use player.Load(GetStreamFromFile("mysound.wav")); where GetStreamFromFile is basically
Stream GetStreamFromFile(string filename)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("App." + filename);
// Obviously App in the line above should be replaced with your app
return stream;
}
And secondly you have to player.Load(GetStreamFromFile("Subfolder.mysound.wav")); where Subfolder is the name of your subfolder.

This block contains invalid or unexpected content on Custom HTML

I am editing a document in draft mode Wordpress 5.2.2 in the Gutenberg editor, and add this Custom HTML block:
<pre><code class="language-typescript">const simple = &ltT&gt(cl: T) => cl;
class Hero {
constructor(public position: [number, number]) {}
}
interface { hello: number }
const errorOne = &ltT&gt(cl: T) => new cl(); // Cannot use 'new' with an expression whose type lacks a call or construct signature.</code></pre>
and it happily works as expected in preview. I save as draft.
When I return the HTML is ghosted and I get the error in the title. I can convert to HTML and it works again, but then it errors again when I return to it later.
It seems this error is talked about everywhere but the explanations are nonsense and resolve nothing.
If my Custom HTML is valid (which it seems to be), why does it work and then give an error. How do I fix this?
I think the main issue is not converting < & > properly in your code. They are missing the semicolon at the end of the string.
This code is working fine:
<pre><code class="language-typescript">const simple = <T>(cl: T) => cl;
class Hero {
constructor(public position: [number, number]) {}
}
interface { hello: number }
const errorOne = <T>(cl: T) => new cl(); // Cannot use 'new' with an expression whose type lacks a call or construct signature.</code></pre>
When you insert the code with missing semicolon, WordPress saved as is. However, when trying the load the page again WordPress compares the saved content (with missing characters) to the one generated from the block (which is probably attempting to display correct HTML). This process led to an error as both texts were not identical.
If you want to check the error yourself you can check the console through developer tool in your browser (F12 in Chrome).

Adobe illustrator Script paste

I found that command app.paste() but it doesnt return string its just pasting into document text. Basicaly i need command that return clipboard!
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20JavaScript%20Scripting%20Reference.pdf
http://prntscr.com/cg5qtb
I suppose there is no command in Illustrator that will return clipboard data. You can use app.copy() and app.paste() if you want to copy paste between different applications and if you want to use only in Illustrator you can use the duplicate method provided in Illustrator documentation.
app.paste() causes the new layer it creates to be the only selected layer, so you can access the text contents by returning its .contents property like this:
#target illustrator
function getClipboard() {
var doc = app.activeDocument;
var clipboard = '';
app.paste();
clipboard = doc.selection[0].contents;
doc.selection[0].remove();
return clipboard;
}
function main() {
alert( getClipboard() );
}
main();```

Resources