mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-14 18:50:54 +01:00
properly save SVG files, not just as fake PNGs
This commit is contained in:
parent
b83f054bcd
commit
73bb9a18cd
@ -190,7 +190,11 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
tryOpenUri(resultData.data!!, resultData)
|
tryOpenUri(resultData.data!!, resultData)
|
||||||
} else if (requestCode == SAVE_IMAGE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
} else if (requestCode == SAVE_IMAGE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||||
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
||||||
|
if (defaultExtension == SVG) {
|
||||||
|
Svg.saveToOutputStream(this, outputStream, my_canvas)
|
||||||
|
} else {
|
||||||
saveToOutputStream(outputStream, defaultPath.getCompressionFormat(), false)
|
saveToOutputStream(outputStream, defaultPath.getCompressionFormat(), false)
|
||||||
|
}
|
||||||
savedPathsHash = my_canvas.getDrawingHashCode()
|
savedPathsHash = my_canvas.getDrawingHashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,15 @@ import java.util.*
|
|||||||
|
|
||||||
object Svg {
|
object Svg {
|
||||||
fun saveSvg(activity: SimpleActivity, path: String, canvas: MyCanvas) {
|
fun saveSvg(activity: SimpleActivity, path: String, canvas: MyCanvas) {
|
||||||
val backgroundColor = (canvas.background as ColorDrawable).color
|
|
||||||
|
|
||||||
activity.getFileOutputStream(FileDirItem(path, path.getFilenameFromPath()), true) {
|
activity.getFileOutputStream(FileDirItem(path, path.getFilenameFromPath()), true) {
|
||||||
if (it != null) {
|
saveToOutputStream(activity, it, canvas)
|
||||||
val writer = BufferedWriter(OutputStreamWriter(it))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveToOutputStream(activity: SimpleActivity, outputStream: OutputStream?, canvas: MyCanvas) {
|
||||||
|
if (outputStream != null) {
|
||||||
|
val backgroundColor = (canvas.background as ColorDrawable).color
|
||||||
|
val writer = BufferedWriter(OutputStreamWriter(outputStream))
|
||||||
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
|
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
|
||||||
writer.close()
|
writer.close()
|
||||||
activity.toast(R.string.file_saved)
|
activity.toast(R.string.file_saved)
|
||||||
@ -30,7 +34,6 @@ object Svg {
|
|||||||
activity.toast(R.string.unknown_error_occurred)
|
activity.toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map<MyPath, PaintOptions>, width: Int, height: Int) {
|
private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map<MyPath, PaintOptions>, width: Int, height: Int) {
|
||||||
writer.apply {
|
writer.apply {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user